From 746c14838c931b11c822d3b33b1d226aeb6352c9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 28 Nov 2023 15:32:10 -0500 Subject: [PATCH] SFR_1826_NYPLLoginFlag --- CHANGELOG.md | 5 +++++ scripts/__init__.py | 3 ++- scripts/nyplLoginFlags.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/nyplLoginFlags.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ddaafcd72..5eb69288c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## unreleased version -- v0.12.4 +## Added +- New script to add nypl_login flag to Links objects +## Fixed + ## 2023-09-05 version -- v0.12.3 ## Removed - The "*" character is escaped from queries passed to ElasticSearch, limiting wildcard searches 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