Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active February 18, 2025 16:55
Show Gist options
  • Save edsu/24d0d6af9a30e2b3aee1c743b3f259a9 to your computer and use it in GitHub Desktop.
Save edsu/24d0d6af9a30e2b3aee1c743b3f259a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# This program will fetch the first page of recently updated Library of Congress
# Subject Headings from id.loc.gov and print out the MARC records for them.
#
# /// script
# dependencies = ["requests", "pymarc"]
# ///
#
# see PEP 723
import io
import pymarc
import requests
def print_marc(url):
marc_xml = io.StringIO(requests.get(url).text)
record = pymarc.marcxml.parse_xml_to_array(marc_xml)[0]
print(str(record))
feed = requests.get('https://id.loc.gov/authorities/names/activitystreams/feed/1.json').json()
for item in feed['orderedItems']:
for url in item['object']['url']:
if url['mediaType'] == 'application/marc+xml':
print_marc(url['href'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment