Skip to content

Commit

Permalink
Merge pull request #270 from NYPL/SFR-1742v2_CountCABooks
Browse files Browse the repository at this point in the history
SFR-1742v2_CountCABooks
  • Loading branch information
mitri-slory authored Aug 8, 2023
2 parents c00f888 + ffbd0a6 commit a7b4fef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
22 changes: 0 additions & 22 deletions UofSC_metadata.json

This file was deleted.

36 changes: 27 additions & 9 deletions scripts/countCABooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import json
import uuid

from model import Record, Work, Edition, Identifier
from model.postgres.edition import EDITION_IDENTIFIERS

from model import Record
from managers import DBManager


Expand All @@ -21,24 +24,39 @@ def main():

dbManager.createSession()

count = 0
editionCount = 0
workCount = 0
UCBooksDRB = []
editionIDS = []
editionWorkID = None

with open('UCBooks.json') as f:
UCBooks = json.load(f)

for sourceID in UCBooks:
record = dbManager.session.query(Record).filter(Record.source_id == f'{sourceID}|hathi').first()
if record:
UCBooksDRB.append(f'{record.id}|{record.source_id}')
count += 1
for record in dbManager.session.query(Record) \
.filter(Record.source_id == f'{sourceID}|hathi').all():
if record:
for edition in dbManager.session.query(Edition) \
.join(EDITION_IDENTIFIERS) \
.join(Identifier) \
.filter(Identifier.identifier == sourceID) \
.filter(Identifier.authority == 'hathi').all():
editionIDS.append(edition.id)
editionCount += 1
editionWorkID = edition.work_id

for work in dbManager.session.query(Work) \
.filter(Work.id == editionWorkID).all():
UCBooksDRB.append({'record': record.source_id, 'edition': editionIDS, 'work': work.uuid})
workCount += 1
editionIDS = []

print(UCBooksDRB)
print(count)
print(editionCount, workCount)
print(editionCount + workCount)

dbManager.closeConnection()

if __name__ == '__main__':
main()


0 comments on commit a7b4fef

Please sign in to comment.