-
-
Save kathrin77/5c2f0dfacc6698bf84ac148c36d06ea8 to your computer and use it in GitHub Desktop.
###Get zenodo community statistics
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='', encoding='utf-8') 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
Zenodo community stats
Get zenodo community statistics with this script:
python stats.py
If you're opening the CSV file "output.csv" in Excel and encountering issues with character encoding, there are a few steps you can take within Excel to try to correct the problem:
Import Data Wizard:
Instead of directly opening the CSV file, try using Excel's "Import Data" wizard. This wizard allows you to specify the file origin and encoding before importing the data into Excel.