Created
July 1, 2022 20:09
-
-
Save caseydm/f999f8462d0d432e63fecbc52588ceb8 to your computer and use it in GitHub Desktop.
OpenAlex citation counts
This file contains hidden or 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
import requests | |
def get_citation_counts(): | |
# sample author | |
author_id = "https://openalex.org/A2151238091" | |
# get up to 50 works for this author | |
r2 = requests.get( | |
f"https://api.openalex.org/works?filter=authorships.author.id:{author_id}" | |
) | |
# go through each work, then count how many other works cite it in a given year | |
years = range(2000, 2023) | |
result = dict() | |
for work in r2.json()["results"]: | |
for year in years: | |
r3 = requests.get( | |
f"https://api.openalex.org/works?filter=publication_year:{year},cites:{work['id']}" | |
) | |
citation_count = r3.json()["meta"]["count"] | |
if year not in result: | |
result[year] = citation_count | |
else: | |
result[year] = result[year] + citation_count | |
# result for those 50 works from 2000-2022 | |
print(result) | |
# { | |
# 2000: 0, | |
# 2001: 0, | |
# 2002: 0, | |
# 2003: 0, | |
# 2004: 0, | |
# 2005: 0, | |
# 2006: 0, | |
# 2007: 0, | |
# 2008: 0, | |
# 2009: 0, | |
# 2010: 1, | |
# 2011: 2, | |
# 2012: 0, | |
# 2013: 1, | |
# 2014: 6, | |
# 2015: 4, | |
# 2016: 8, | |
# 2017: 5, | |
# 2018: 4, | |
# 2019: 2, | |
# 2020: 4, | |
# 2021: 19, | |
# 2022: 14, | |
# } | |
if __name__ == "__main__": | |
get_citation_counts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment