Skip to content

Commit

Permalink
Merge pull request #277 from NYPL/SFR-1826_NYPLLoginFlag
Browse files Browse the repository at this point in the history
SFR_1826_NYPLLoginFlag
  • Loading branch information
mitri-slory authored Dec 11, 2023
2 parents d14eab0 + e46bcb1 commit a1f59a0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion mappings/nypl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
))
3 changes: 2 additions & 1 deletion scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from .countCABooks import main as countCA
from .nyplLoginFlags import main as nyplFlags
35 changes: 35 additions & 0 deletions scripts/nyplLoginFlags.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion tests/unit/test_nypl_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
]

0 comments on commit a1f59a0

Please sign in to comment.