Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFR-2288 Querying by OCLC Number uses metadata API MARCXML endpoint #464

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

Apophenia
Copy link
Contributor

@Apophenia Apophenia commented Dec 3, 2024

  • Removes search v1 endpoint and instead uses metadata v2
  • Requests key with reduced scope (this is now required, since key no longer has access to full read/write API actions)
  • Strips OCLC prefixes from OCLC control numbers when applying mapping: there are a few thousand records in QA that are prefixed, from various sources. However, the great majority of OCLC numbers are not prefixed and I created a function to remove the prefixes, as we do for e.g. Project MUSE

Tested with the SeedLocalData process and fields were manually compared -- after removing OCLC control number prefixes, they now look comparable at a glance.

@Apophenia Apophenia marked this pull request as ready for review December 3, 2024 22:46
@@ -16,7 +16,7 @@ class OCLCAuthManager:
_metadata_token = None
_metadata_token_expires_at = None
OCLC_SEARCH_AUTH_URL = 'https://oauth.oclc.org/token?scope=wcapi&grant_type=client_credentials'
OCLC_METADATA_AUTH_URL = 'https://oauth.oclc.org/token?scope=WorldCatMetadataAPI&grant_type=client_credentials'
OCLC_METADATA_AUTH_URL = 'https://oauth.oclc.org/token?scope=WorldCatMetadataAPI:view_marc_bib&grant_type=client_credentials'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines 23 to 24
def remove_oclc_prefixes(self, oclc_id):
return oclc_id.removeprefix('(OCoLC)').removeprefix('on').removeprefix('ocn').removeprefix('ocm')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend pulling up prefixes into a set or list above as a constant, e.g. OCLC_PREFIXES = ['(OCoLC)', 'on', 'ocn', 'ocm'].

That way we can just do:

for prefix in OCLC_PREFIXES:
  oclc_id = oclc_id.removeprefix(prefix)

In theory ha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Copy link
Contributor

@kylevillegas93 kylevillegas93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Overall looks great - just 1 minor function improvement

Copy link
Contributor

@kylevillegas93 kylevillegas93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@Apophenia Apophenia merged commit 5d49d08 into main Dec 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants