diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ddaafcd72..d4f078c6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## unreleased version -- v0.12.4 +## Added +- New script to add nypl_login flag to Links objects +- Added nypl_login flag to nypl mapping +## Fixed + ## 2023-09-05 version -- v0.12.3 ## Removed - The "*" character is escaped from queries passed to ElasticSearch, limiting wildcard searches diff --git a/mappings/nypl.py b/mappings/nypl.py index cf5d905296..1896d97d88 100644 --- a/mappings/nypl.py +++ b/mappings/nypl.py @@ -144,7 +144,7 @@ def applyFormatting(self): item['location']['code'], item['location']['name'], pos )) - self.record.has_part.append('{}|{}|nypl|application/x.html+edd|{{"edd": true, "catalog": false, "download": false, "reader": false}}'.format( + self.record.has_part.append('{}|{}|nypl|application/x.html+edd|{{"edd": true, "catalog": false, "download": false, "reader": false, "nypl_login": true}}'.format( pos, 'http://www.nypl.org/research/collections/shared-collection-catalog/hold/request/b{}-i{}'.format(self.source['id'], item['id']) )) \ No newline at end of file diff --git a/scripts/__init__.py b/scripts/__init__.py index 543f0ed5e1..f0366b114f 100644 --- a/scripts/__init__.py +++ b/scripts/__init__.py @@ -11,4 +11,5 @@ from .interstitialPagesSFR1410 import main as interstitialPages from .ingestS3Metadata import main as ingestS3 from .updatePubLocationAndLinks import main as updateLocationAndLinks -from .countCABooks import main as countCABooks \ No newline at end of file +from .countCABooks import main as countCA +from .nyplLoginFlags import main as nyplFlags \ No newline at end of file diff --git a/scripts/nyplLoginFlags.py b/scripts/nyplLoginFlags.py new file mode 100644 index 0000000000..9911b8fb21 --- /dev/null +++ b/scripts/nyplLoginFlags.py @@ -0,0 +1,35 @@ +import os + +from model import Link +from managers import DBManager +from sqlalchemy import or_ +import json + +def main(): + + '''Updating NYPL Link flags with a new nypl_login flag''' + + dbManager = DBManager( + user= os.environ.get('POSTGRES_USER', None), + pswd= os.environ.get('POSTGRES_PSWD', None), + host= os.environ.get('POSTGRES_HOST', None), + port= os.environ.get('POSTGRES_PORT', None), + db= os.environ.get('POSTGRES_NAME', None) + ) + + dbManager.generateEngine() + + dbManager.createSession() + + for link in dbManager.session.query(Link) \ + .filter(or_(Link.media_type == 'application/html+edd', Link.media_type == 'application/x.html+edd')).all(): + if link.flags['edd'] == True: + #The link.flags doesn't update if the dict method isn't called on it + newLinkFlag = dict(link.flags) + newLinkFlag['nypl_login'] = True + link.flags = newLinkFlag + + dbManager.commitChanges() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/tests/unit/test_nypl_mapping.py b/tests/unit/test_nypl_mapping.py index 7e0ff892ed..366509a10b 100644 --- a/tests/unit/test_nypl_mapping.py +++ b/tests/unit/test_nypl_mapping.py @@ -104,5 +104,5 @@ def test_applyFormatting(self, testMapping, testRecord_standard, testBibItems, t assert testMapping.record.coverage == ['tst|Test|2'] assert testMapping.record.has_part == [ '1|https://www.nypl.org/research/collections/shared-collection-catalog/bib/b1|nypl|application/html+catalog|{"catalog": true, "download": false, "reader": false}', - '2|http://www.nypl.org/research/collections/shared-collection-catalog/hold/request/b1-i1|nypl|application/x.html+edd|{"edd": true, "catalog": false, "download": false, "reader": false}' + '2|http://www.nypl.org/research/collections/shared-collection-catalog/hold/request/b1-i1|nypl|application/x.html+edd|{"edd": true, "catalog": false, "download": false, "reader": false, "nypl_login": true}' ]