diff --git a/_config.yml b/_config.yml index 0b237de..cf87e62 100644 --- a/_config.yml +++ b/_config.yml @@ -2,7 +2,7 @@ title: Scholarly API Cookbook author: The University of Alabama Libraries -copyright: "2023" +copyright: "2024" logo: images/UALIB_logo.png exclude_patterns: [old, conversion_scripts] # Force re-execution of notebooks on each build. diff --git a/_toc.yml b/_toc.yml index 16806d4..1310d52 100644 --- a/_toc.yml +++ b/_toc.yml @@ -26,6 +26,9 @@ parts: - file: content/scripts/mathematica/mathematica_crossref - file: content/scripts/R/R_Crossref - file: content/scripts/C/C_CrossRef + - file: content/scripts/A_overview/ror_overview + sections: + - file: content/scripts/python/python_ror - file: content/scripts/A_overview/scopus_overview sections: - file: content/scripts/python/python_scopus diff --git a/content/scripts/A_overview/ror_overview.rst b/content/scripts/A_overview/ror_overview.rst new file mode 100644 index 0000000..59fa943 --- /dev/null +++ b/content/scripts/A_overview/ror_overview.rst @@ -0,0 +1,18 @@ +Research Organization Registry (ROR) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +.. sectionauthor:: Michael T. Moen + +Brief Overview +**************** + +The Research Organization Registry (ROR) API provides programmatic access to the organization's persistent identifiers for research organizations. An API key is not required for this API, but they do require you to and follow their rate limit of 2000 requests per five minute period. + +See the ROR API documentation [#ror1]_ for more information on accessing the API. Note that the data in the API is licensed under the Creative Commons CC0 license [#ror2]_ , designating it as part of the public domain. + +.. rubric:: References + +.. [#ror1] ``_ + +.. [#ror2] ``_ + diff --git a/content/scripts/python/python_ror.ipynb b/content/scripts/python/python_ror.ipynb new file mode 100644 index 0000000..600bb72 --- /dev/null +++ b/content/scripts/python/python_ror.ipynb @@ -0,0 +1,718 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# ...in Python" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Research Organization Registry (ROR) in Python\n", + "\n", + "by Michael T. Moen\n", + "\n", + "**ROR API documentation:** https://ror.readme.io/docs/rest-api\n", + "\n", + "**ROR API license:** https://ror.readme.io/docs/ror-basics#what-is-ror\n", + "\n", + "The ROR API is licensed under the Creative Commons' [CC0 license](https://creativecommons.org/publicdomain/zero/1.0/), designating its data as part of the public domain.\n", + "\n", + "
\n", + "\n", + "The Research Organization Registry (ROR) API provides persistent identifiers for research organizations.\n", + "\n", + "These recipe examples were tested on January 19, 2023.\n", + "\n", + "**_NOTE:_** The ROR API limits requests to a maximum of 2000 requests in a 5-minute period." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### ROR Data Dump\n", + "\n", + "When working with larger datasets, consider using the ROR data dump: https://ror.readme.io/docs/data-dump" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setup\n", + "\n", + "This tutorial uses the following libraries:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import requests # Manages API requests\n", + "from urllib.parse import quote # URL encodes string inputs\n", + "from time import sleep # Allows staggering of API requests to conform to rate limits" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. Searching with queries\n", + "\n", + "This first example uses the `query` parameter of the ROR API to search for an institution by name. In this example, we'll search for The University of Alabama:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total number of results: 25434\n", + "Page length: 20\n" + ] + } + ], + "source": [ + "# The search query is the institution name\n", + "institution = 'University of Alabama'\n", + "\n", + "# Use the quote() function to URL encode our search term\n", + "url = f'https://api.ror.org/organizations?query={quote(institution)}'\n", + "response = requests.get(url).json()\n", + "\n", + "# Print total number of results and number of results in page\n", + "print(f'Total number of results: {response['number_of_results']}')\n", + "print(f'Page length: {len(response['items'])}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The results indicate that the query produced thousands of results, but only the data for 20 institutions were returned in this query. However, the top result was exactly what we were looking for:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "tags": [ + "output_scroll" + ] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'https://ror.org/03xrrjk67',\n", + " 'name': 'University of Alabama',\n", + " 'email_address': None,\n", + " 'ip_addresses': [],\n", + " 'established': 1831,\n", + " 'types': ['Education'],\n", + " 'relationships': [{'label': 'Mississippi Alabama Sea Grant Consortium',\n", + " 'type': 'Related',\n", + " 'id': 'https://ror.org/04vzsq290'},\n", + " {'label': 'University of Alabama System',\n", + " 'type': 'Parent',\n", + " 'id': 'https://ror.org/051fvmk98'}],\n", + " 'addresses': [{'lat': 33.20984,\n", + " 'lng': -87.56917,\n", + " 'state': None,\n", + " 'state_code': None,\n", + " 'city': 'Tuscaloosa',\n", + " 'geonames_city': {'id': 4094455,\n", + " 'city': 'Tuscaloosa',\n", + " 'geonames_admin1': {'name': 'Alabama',\n", + " 'id': 4829764,\n", + " 'ascii_name': 'Alabama',\n", + " 'code': 'US.AL'},\n", + " 'geonames_admin2': {'name': 'Tuscaloosa',\n", + " 'id': 4094463,\n", + " 'ascii_name': 'Tuscaloosa',\n", + " 'code': 'US.AL.125'},\n", + " 'license': {'attribution': 'Data from geonames.org under a CC-BY 3.0 license',\n", + " 'license': 'http://creativecommons.org/licenses/by/3.0/'},\n", + " 'nuts_level1': {'name': None, 'code': None},\n", + " 'nuts_level2': {'name': None, 'code': None},\n", + " 'nuts_level3': {'name': None, 'code': None}},\n", + " 'postcode': None,\n", + " 'primary': False,\n", + " 'line': None,\n", + " 'country_geonames_id': 6252001}],\n", + " 'links': ['https://www.ua.edu/'],\n", + " 'aliases': [],\n", + " 'acronyms': [],\n", + " 'status': 'active',\n", + " 'wikipedia_url': 'http://en.wikipedia.org/wiki/University_of_Alabama',\n", + " 'labels': [{'label': 'Universidad de Alabama', 'iso639': 'es'},\n", + " {'label': \"Université de l'Alabama\", 'iso639': 'fr'}],\n", + " 'country': {'country_name': 'United States', 'country_code': 'US'},\n", + " 'external_ids': {'ISNI': {'preferred': None, 'all': ['0000 0001 0727 7545']},\n", + " 'FundRef': {'preferred': '100011531', 'all': ['100011531']},\n", + " 'OrgRef': {'preferred': None, 'all': ['327950']},\n", + " 'Wikidata': {'preferred': None, 'all': ['Q492318']},\n", + " 'GRID': {'preferred': 'grid.411015.0', 'all': 'grid.411015.0'}}}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Display data of the top search result\n", + "response['items'][0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following code produces the name, ROR ID, city, and wikipedia URL of the top result of the query:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'University of Alabama'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response['items'][0]['name']" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://ror.org/03xrrjk67'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response['items'][0]['id']" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Tuscaloosa'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response['items'][0]['addresses'][0]['city']" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'http://en.wikipedia.org/wiki/University_of_Alabama'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response['items'][0]['wikipedia_url']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Searching by alternate names\n", + "\n", + "The example below uses abbreviated forms of the full names of universities when searching:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "University of Alabama Tuscaloosa: University of Alabama\n", + "Missouri: Missouri Southern State University\n", + "Dartmouth: Dartmouth Psychiatric Research Center\n", + "Oxford: Stockholm Environment Institute\n", + "UCLA: Universidad Centroccidental Lisandro Alvarado\n" + ] + } + ], + "source": [ + "# List of institutions to be searched\n", + "institutions = [\n", + " 'University of Alabama Tuscaloosa',\n", + " 'Missouri',\n", + " 'Dartmouth',\n", + " 'Oxford',\n", + " 'UCLA'\n", + "]\n", + "\n", + "# Send an HTTP request for each institution\n", + "for institution in institutions:\n", + "\n", + " # Use the quote() function to URL encode our search term\n", + " url = f'https://api.ror.org/organizations?query={quote(institution)}'\n", + " search_data = requests.get(url).json()\n", + "\n", + " # Print the search term and the name of its top result\n", + " print(f'{institution}: {search_data['items'][0]['name']}')\n", + "\n", + " # Stagger requests to be nicer on the ROR servers\n", + " sleep(0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The top results of the queries above are probably not what you would have expected. The example below remedies these issues by having more clearly defined search strings:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "University of Alabama Tuscaloosa: University of Alabama\n", + "University of Missouri: University of Missouri\n", + "Dartmouth College: Dartmouth College\n", + "University of Oxford: University of Oxford\n", + "University of California Los Angeles: University of California, Los Angeles\n" + ] + } + ], + "source": [ + "# List of institutions to be searched\n", + "institutions = [\n", + " 'University of Alabama Tuscaloosa',\n", + " 'University of Missouri',\n", + " 'Dartmouth College',\n", + " 'University of Oxford',\n", + " 'University of California Los Angeles'\n", + "]\n", + "\n", + "# Send an HTTP request for each institution\n", + "for institution in institutions:\n", + "\n", + " # Use the quote() function to URL encode our search term\n", + " url = f'https://api.ror.org/organizations?query={quote(institution)}'\n", + " search_data = requests.get(url).json()\n", + "\n", + " # Print the search term and the name of its top result\n", + " print(f'{institution}: {search_data['items'][0]['name']}')\n", + "\n", + " # Stagger requests to be nicer on the ROR servers\n", + " sleep(0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Searching with filters\n", + "\n", + "The ROR API also allows searches to be performed with the `filter` parameter, which can take 3 arguments: `status`, `types`, and `country`. For more information on what values these arguments can take, read the ROR documentation here: https://ror.org/tutorials/intro-ror-api/#filtering-results" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4296" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Filters are separated by commas\n", + "filters = ','.join([\n", + " f'country.country_name:{quote(\"United States\")}',\n", + " 'types:Education',\n", + " 'status:Active'\n", + "])\n", + "\n", + "# URL constructed with the filters\n", + "url = f'https://api.ror.org/organizations?filter={filters}'\n", + "response = requests.get(url).json()\n", + "\n", + "# Display number of results\n", + "response['number_of_results']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Paging through a result\n", + "\n", + "The example below pages through the results to find the names and ROR IDs of the first 100 institutions returned using the filter:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "tags": [ + "output_scroll" + ] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "American Society for Microbiology: https://ror.org/04xsjmh40\n", + "Austin College: https://ror.org/052k56z27\n", + "Austin Community College: https://ror.org/044tz3m61\n", + "Bacone College: https://ror.org/03rvph505\n", + "Bakersfield College: https://ror.org/00tz9e151\n", + "Baltimore City Community College: https://ror.org/03b286288\n", + "Bank Street College of Education: https://ror.org/04v44vh53\n", + "Bay Mills Community College: https://ror.org/005m1kj18\n", + "Bellingham Technical College: https://ror.org/03hjr5c64\n", + "Bishop State Community College: https://ror.org/036vmnd51\n", + "Bismarck State College: https://ror.org/042fn4q48\n", + "Bittersweet Farms: https://ror.org/02j7zcz08\n", + "Blackfeet Community College: https://ror.org/02kgm7r43\n", + "Bloomfield College: https://ror.org/04gdk0x87\n", + "Bluffton University: https://ror.org/05pacqm37\n", + "Boston Public Schools: https://ror.org/03bj7kr91\n", + "Bristol Community College: https://ror.org/05e168j76\n", + "Burlington School District: https://ror.org/00zbcp540\n", + "Calallen Independent School District: https://ror.org/00p5kvd83\n", + "California FarmLink: https://ror.org/02dz8kh28\n", + "California Teaching Fellows Foundation: https://ror.org/00j7csj22\n", + "College of Central Florida: https://ror.org/0354w0y78\n", + "DeKalb County School District: https://ror.org/03ka3vc13\n", + "Drummond Public Schools: https://ror.org/003p7hq46\n", + "Dublin Independent School District: https://ror.org/04hm48b29\n", + "Earth Learning: https://ror.org/01wzgqz67\n", + "Eastern Florida State College: https://ror.org/04tw5da48\n", + "Ecpi University: https://ror.org/04133ks15\n", + "Fielding Graduate University: https://ror.org/04csg5w40\n", + "Harding University Main Campus: https://ror.org/00t4cvq91\n", + "Hartnell College: https://ror.org/013yab158\n", + "Hawkeye Community College: https://ror.org/02b1scj45\n", + "Honolulu Community College: https://ror.org/00vpw9h05\n", + "Horry County Schools: https://ror.org/021x5j769\n", + "Iḷisaġvik College: https://ror.org/00mw3fh49\n", + "Judge Baker Children's Center: https://ror.org/05tby3y60\n", + "Louisiana State University System: https://ror.org/022gnbj15\n", + "Maricopa County Community College District: https://ror.org/004kyan19\n", + "Minnesota Agriculture in the Classroom Foundation: https://ror.org/0497prz03\n", + "Mobile County Public Schools: https://ror.org/00dtfmh68\n", + "Navajo Technical University: https://ror.org/05jkpmg51\n", + "New York Academy of Medicine: https://ror.org/00mwdv335\n", + "Northwestern Health Sciences University: https://ror.org/00186jw56\n", + "Oakton Community College: https://ror.org/020bcb226\n", + "Oglala Lakota College: https://ror.org/012y1mj37\n", + "Ohio Dominican University: https://ror.org/00pmncr36\n", + "Omak School District: https://ror.org/03vp4wk44\n", + "Philadelphia College of Osteopathic Medicine: https://ror.org/00m9c2804\n", + "Piedmont Technical College: https://ror.org/039y7c549\n", + "Piedmont Virginia Community College: https://ror.org/02tw58061\n", + "Pima Community College: https://ror.org/00wymkh76\n", + "Salus University: https://ror.org/00p82hn55\n", + "Social Sciences Innovations: https://ror.org/04b3jmc64\n", + "Southern Illinois University School of Medicine: https://ror.org/0232r4451\n", + "State University of New York College of Optometry: https://ror.org/02v9m6h26\n", + "Tennessee State University: https://ror.org/01fpczx89\n", + "Toyota Technological Institute at Chicago: https://ror.org/02sn5gb64\n", + "Truckee Meadows Community College: https://ror.org/04c0sqe08\n", + "University System of Georgia: https://ror.org/017wcm924\n", + "University System of New Hampshire: https://ror.org/0061x0487\n", + "University of Houston - Clear Lake: https://ror.org/01t817z14\n", + "University of Massachusetts Donahue Institute: https://ror.org/057e34m22\n", + "University of Nevada, Las Vegas: https://ror.org/0406gha72\n", + "University of Wisconsin–Extension: https://ror.org/05mdm7050\n", + "Valparaiso University: https://ror.org/01pp0fx48\n", + "Virginia Military Institute: https://ror.org/01ngnm118\n", + "Virginia State University: https://ror.org/04esvpn06\n", + "Virginia Union University: https://ror.org/02zwyfg51\n", + "Viterbo University: https://ror.org/039p8pn96\n", + "Wabash College: https://ror.org/00p11pk44\n", + "Washburn University: https://ror.org/04sk2ar21\n", + "Weber State University: https://ror.org/01epn2q93\n", + "Wesleyan University: https://ror.org/05h7xva58\n", + "West Virginia University: https://ror.org/011vxgd24\n", + "West Virginia University at Parkersburg: https://ror.org/00k5m1279\n", + "West Virginia Wesleyan College: https://ror.org/057nqxc22\n", + "Western Carolina University: https://ror.org/010h78f45\n", + "Western Kentucky University: https://ror.org/0446vnd56\n", + "Western Michigan University: https://ror.org/04j198w64\n", + "Western New England University: https://ror.org/007cnf143\n", + "Western New Mexico University: https://ror.org/00r5mr697\n", + "Western Oklahoma State College: https://ror.org/03tktyg33\n", + "Western Oregon University: https://ror.org/002xn4752\n", + "Westmont College: https://ror.org/00xhcz327\n", + "Wheeling Jesuit University: https://ror.org/02z310y44\n", + "Whitman College: https://ror.org/05axv8155\n", + "Whitworth University: https://ror.org/04j9d0s43\n", + "Wichita State University: https://ror.org/00c4e7y75\n", + "Wilberforce University: https://ror.org/02b50zn53\n", + "Willamette University: https://ror.org/04g9e0f44\n", + "William Woods University: https://ror.org/05ktv1y25\n", + "Williams College: https://ror.org/04avkmd49\n", + "Wilson College: https://ror.org/05japer20\n", + "Winston-Salem State University: https://ror.org/049yc0897\n", + "Winthrop University: https://ror.org/04mpzkf73\n", + "Wittenberg University: https://ror.org/04a23br85\n", + "Worcester State University: https://ror.org/04j8de466\n", + "Xavier University: https://ror.org/00f266q65\n", + "York College, City University of New York: https://ror.org/015a1ak54\n", + "Youngstown State University: https://ror.org/038zf2n28\n" + ] + } + ], + "source": [ + "# Filters to are separated by commas\n", + "filters = ','.join([\n", + " f'country.country_name:{quote(\"United States\")}',\n", + " 'types:Education',\n", + " 'status:Active'\n", + "])\n", + "\n", + "# URL constructed with the filters\n", + "url = f'https://api.ror.org/organizations?filter={filters}'\n", + "response = requests.get(url).json()\n", + "\n", + "# Calculate number of pages in result\n", + "total_pages = (response['number_of_results'] // len(response['items'])) + 1\n", + "\n", + "# Store resulting names in a dictionary\n", + "institution_rors = {}\n", + "\n", + "# Limited to first 5 pages for this tutorial\n", + "for page_number in range(total_pages)[:5]:\n", + "\n", + " # Use the quote() function to URL encode our search term\n", + " url = f'https://api.ror.org/organizations?filter={filters}&page={page_number+1}'\n", + " search_data = requests.get(url).json()\n", + "\n", + " # Add institution names and ROR IDs to the institution_results list\n", + " for result in search_data['items']:\n", + " institution_rors[result['name']] = result['id']\n", + "\n", + " # Stagger requests to be nicer on the ROR servers\n", + " sleep(0.5)\n", + "\n", + "# Display first 100 results\n", + "for name, ror_id in sorted(institution_rors.items()):\n", + " print(f'{name}: {ror_id}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The resulting dictionary can be used to find the ROR of an institution based on its name:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://ror.org/00f266q65'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "institution_rors['Xavier University']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Searching with queries and filters\n", + "\n", + "The `filter` and `query` parameters can both be used in a single request. In this example, we filter the results of the query \"Birmingham\" to only include institutions from the United States:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Filter results to the United States\n", + "filter = f'country.country_name:{quote(\"United States\")}'\n", + "\n", + "# Search term\n", + "query = 'Birmingham'\n", + "\n", + "# URL constructed with the filters\n", + "url = f'https://api.ror.org/organizations?query={query}&filter={filter}'\n", + "response = requests.get(url).json()\n", + "\n", + "# Display number of results\n", + "response['number_of_results']" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Alabama Audubon: https://ror.org/02qbyex13\n", + "Birmingham Bloomfield Community Coalition: https://ror.org/004mx7t23\n", + "Birmingham Civil Rights Institute: https://ror.org/00fqce595\n", + "Birmingham Museum of Art: https://ror.org/030y6zg68\n", + "Birmingham Public Library: https://ror.org/05czff141\n", + "Birmingham VA Medical Center: https://ror.org/0242qs713\n", + "Birmingham–Southern College: https://ror.org/006g42111\n", + "St. Vincent's Birmingham: https://ror.org/000crk757\n", + "UAB Medicine: https://ror.org/036554539\n", + "University of Alabama at Birmingham: https://ror.org/008s83205\n", + "University of Alabama at Birmingham Hospital: https://ror.org/01rm42p40\n", + "Vision Specialists of Michigan: https://ror.org/02awhp844\n" + ] + } + ], + "source": [ + "# Filter results to the United States\n", + "filter = f'country.country_name:{quote(\"United States\")}'\n", + "\n", + "# Search term\n", + "query = 'Birmingham'\n", + "\n", + "# URL constructed with the filters\n", + "url = f'https://api.ror.org/organizations?query={query}&filter={filter}'\n", + "response = requests.get(url).json()\n", + "\n", + "# Calculate number of pages in result\n", + "total_pages = (response['number_of_results'] // len(response['items'])) + 1\n", + "\n", + "# Store resulting names in a dictionary\n", + "institution_rors = {}\n", + "\n", + "# Limited to first 5 pages for this tutorial\n", + "for page_number in range(total_pages):\n", + "\n", + " # Use the quote() function to URL encode our search term\n", + " url = f'https://api.ror.org/organizations?query={query}&filter={filter}&page={page_number+1}'\n", + " search_data = requests.get(url).json()\n", + "\n", + " # Add institution names and ROR IDs to the institution_results list\n", + " for result in search_data['items']:\n", + " institution_rors[result['name']] = result['id']\n", + "\n", + " # Stagger requests to be nicer on the ROR servers\n", + " sleep(0.5)\n", + "\n", + "# Display first 100 results\n", + "for name, ror_id in sorted(institution_rors.items()):\n", + " print(f'{name}: {ror_id}')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "env1", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.0" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}