Skip to content

Instantly share code, notes, and snippets.

@lnielsen
Created April 25, 2024 20:19
Show Gist options
  • Save lnielsen/763b29e148dc53ad76e75df3767f9d19 to your computer and use it in GitHub Desktop.
Save lnielsen/763b29e148dc53ad76e75df3767f9d19 to your computer and use it in GitHub Desktop.
from urllib.request import Request, urlopen
from urllib.parse import quote_plus
import json
import csv
query = "communities:lory"
filename = "output.csv"
query = quote_plus(query)
link = f'https://zenodo.org/api/records?all_versions=true&size=200&q={query}'
def request(link, writer):
with urlopen(Request(link)) as r:
data = json.loads(r.read())
next_link = data['links'].get('next', None)
for h in data['hits']['hits']:
self_link = h['links']['self']
doi = h['metadata']['doi']
title = h['metadata']['title']
date = h['metadata']['publication_date']
views = h['stats']['views']
downloads = h['stats']['downloads']
writer.writerow([self_link, doi, title, date, views, downloads])
return next_link
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["URL","DOI","Title","PublicationDate","Views","Downloads"])
print(f"Requesting {link}")
link = request(link, writer)
while link:
print(f"Requesting {link}")
link = request(link, writer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment