Skip to content

Instantly share code, notes, and snippets.

@edsu
Last active July 8, 2024 22:42
Show Gist options
  • Save edsu/c01a836427464d5c854d5c566298b402 to your computer and use it in GitHub Desktop.
Save edsu/c01a836427464d5c854d5c566298b402 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Run this program with an institution name and see the institutions and the count
of publications in OpenAlex.
$ ./openalex_counts "stanford"
Stanford University (I97018004): 430550
Stanford Medicine (I4210137306): 32576
Stanford Synchrotron Radiation Lightsource (I4210120900): 12939
Stanford Health Care (I4210105015): 4550
Stanford Blood Center (I4210133340): 510
SRI International (I1298353152): 18418
SLAC National Accelerator Laboratory (I2801935854): 23121
Stanford Cancer Institute (I4390039303): 0
Stanford SystemX Alliance (I4392738099): 0
Stanford Maternal and Child Health Research Institute (I4391767688): 0
Institute for Stem Cell Biology and Regenerative Medicine (I4394709089): 0
"""
import re
import sys
import time
import pyalex
pyalex.config.email = "you@example.com"
institution_name = sys.argv[1]
for inst in pyalex.Institutions().search(institution_name).get():
inst_id = re.sub(r'https://.+/', '', inst['id'])
count = pyalex.Works().filter(institutions={"id": inst_id}).count()
print(f"{inst['display_name']} ({inst_id}): {count}")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment