-
-
Save lnielsen/763b29e148dc53ad76e75df3767f9d19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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