Skip to content

Instantly share code, notes, and snippets.

@afandian
Created August 24, 2016 10:56
Show Gist options
  • Save afandian/034de2645fbf7923580939b9d53197bc to your computer and use it in GitHub Desktop.
Save afandian/034de2645fbf7923580939b9d53197bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# pip3 install requests
import requests
ignore_prefix = len('http://id.crossref.org/prefix/')
cursor = "*"
prefixes = {}
works = True
while works:
message = requests.get("http://api.crossref.org/works",
params={"cursor": cursor,
"rows": 500,
"filter": "has-clinical-trial-number:true"}).json()['message']
works = message['items']
cursor = message['next-cursor']
for work in works:
prefix = work['prefix'][ignore_prefix:]
prefixes[prefix] = prefixes.get(prefix,0) + 1
total = 0
for prefix, count in prefixes.items():
prefix_owner = requests.get("http://api.crossref.org/prefixes/" + prefix).json()['message']['name']
print("%s\t%s\t%d" % (prefix, prefix_owner, count))
total += count
print("Total: %d" % total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment