-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kenyon
committed
Sep 30, 2022
0 parents
commit 03a6810
Showing
75 changed files
with
17,368 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,335 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Using the PRIMO API\n", | ||
"\n", | ||
"## Download a list of results from PRIMO\n", | ||
"\n", | ||
"PRIMO API is <code>https://api-na.hosted.exlibrisgroup.com/primo/v1/pnxs?</code><br>\n", | ||
"\n", | ||
"UI key = {YOUR KEY HERE}<br>\n", | ||
"\n", | ||
"Scope options:\n", | ||
"* All items = <code>everything</code>\n", | ||
"* UI+Summit = <code>ui_alma_summit</code>\n", | ||
"* UI Only = <code>ui_alma</code>\n", | ||
"\n", | ||
"'vid' parameter is <code>UID</code>\n", | ||
"\n", | ||
"Queries should begin with <code>q=</code>, then other terms, e.g. <code>q=any,contains,sage+grouse</code>\n", | ||
"\n", | ||
"## Retrieve a specific record:\n", | ||
"\n", | ||
"* <code>.../primo/v1/pnxs/{context}/{recordId}</code>\n", | ||
"* context should be either L or PC\n", | ||
"* recordId should be the recId" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import requests\n", | ||
"import pandas as pd\n", | ||
"from time import sleep\n", | ||
"import json" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Need a list of titles to search\n", | ||
"# CSV of pnxId, titles\n", | ||
"# Search by each title, save results to a file\n", | ||
"# Find proquest records for each title, extract id, build URL" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "NameError", | ||
"evalue": "name 'pd' is not defined", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[1;32m<ipython-input-2-c19d774bdb4d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtheses\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'./theses/2021-06-18_fishWildTheses.csv'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"theses = pd.read_csv('./theses/2021-06-18_fishWildTheses.csv')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "NameError", | ||
"evalue": "name 'theses' is not defined", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[1;32m<ipython-input-1-65febfbf61bd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtheses\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[1;31mNameError\u001b[0m: name 'theses' is not defined" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"theses" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"col_list = ['setId', 'title']\n", | ||
"theses = theses[col_list]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"theses['results'] = ''" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div>\n", | ||
"<style scoped>\n", | ||
" .dataframe tbody tr th:only-of-type {\n", | ||
" vertical-align: middle;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe tbody tr th {\n", | ||
" vertical-align: top;\n", | ||
" }\n", | ||
"\n", | ||
" .dataframe thead th {\n", | ||
" text-align: right;\n", | ||
" }\n", | ||
"</style>\n", | ||
"<table border=\"1\" class=\"dataframe\">\n", | ||
" <thead>\n", | ||
" <tr style=\"text-align: right;\">\n", | ||
" <th></th>\n", | ||
" <th>setId</th>\n", | ||
" <th>title</th>\n", | ||
" <th>results</th>\n", | ||
" </tr>\n", | ||
" </thead>\n", | ||
" <tbody>\n", | ||
" <tr>\n", | ||
" <th>0</th>\n", | ||
" <td>6bdbe0ecc13f00c85ec2660f02331c5b</td>\n", | ||
" <td>Applications of geographical information syste...</td>\n", | ||
" <td></td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>1</th>\n", | ||
" <td>52455a4776dcd9b8827ed67547e655f1</td>\n", | ||
" <td>The rainbow trout market in Mexico City</td>\n", | ||
" <td></td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>2</th>\n", | ||
" <td>eb81e31c11650f867c980b37d8340622</td>\n", | ||
" <td>Reproductive ecology of tundra swans on the Ar...</td>\n", | ||
" <td></td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>3</th>\n", | ||
" <td>883f37f1097368babc93f7fcdc2541c2</td>\n", | ||
" <td>Seasonal movements, habitat use, and productiv...</td>\n", | ||
" <td></td>\n", | ||
" </tr>\n", | ||
" <tr>\n", | ||
" <th>4</th>\n", | ||
" <td>1cfe0576f821bec84cedac92565cfd1f</td>\n", | ||
" <td>Winter ecology of migratory sage grouse and as...</td>\n", | ||
" <td></td>\n", | ||
" </tr>\n", | ||
" </tbody>\n", | ||
"</table>\n", | ||
"</div>" | ||
], | ||
"text/plain": [ | ||
" setId \\\n", | ||
"0 6bdbe0ecc13f00c85ec2660f02331c5b \n", | ||
"1 52455a4776dcd9b8827ed67547e655f1 \n", | ||
"2 eb81e31c11650f867c980b37d8340622 \n", | ||
"3 883f37f1097368babc93f7fcdc2541c2 \n", | ||
"4 1cfe0576f821bec84cedac92565cfd1f \n", | ||
"\n", | ||
" title results \n", | ||
"0 Applications of geographical information syste... \n", | ||
"1 The rainbow trout market in Mexico City \n", | ||
"2 Reproductive ecology of tundra swans on the Ar... \n", | ||
"3 Seasonal movements, habitat use, and productiv... \n", | ||
"4 Winter ecology of migratory sage grouse and as... " | ||
] | ||
}, | ||
"execution_count": 16, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"theses.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 117, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Proquest Permanent URL Example:\n", | ||
"# https://uidaho.idm.oclc.org/login?url=https://search.proquest.com/docview/2271755483\n", | ||
"\n", | ||
"def getOutcome(results):\n", | ||
" outcome = []\n", | ||
" results = results.get('docs','Not Found')\n", | ||
" if results == 'Not Found':\n", | ||
" outcome.append('Not Found')\n", | ||
" else:\n", | ||
" for doc in results:\n", | ||
" link = doc['delivery']['GetIt1'][0]['links'][0]['link']\n", | ||
" if 'proquest' in link:\n", | ||
" #print(link)\n", | ||
" groups = link.split(\"/\")\n", | ||
" #print(groups)\n", | ||
" groupsTwo = groups[4].split(\"?\")\n", | ||
" pqNum = groupsTwo[0]\n", | ||
" link = 'https://uidaho.idm.oclc.org/login?url=https://search.proquest.com/docview/'+pqNum\n", | ||
" outcome.append(link)\n", | ||
" else:\n", | ||
" noPQ = \"No Proquest Record Detected\"\n", | ||
" outcome.append(noPQ)\n", | ||
"\n", | ||
" print(outcome)\n", | ||
" theses.at[index, 'results'] = outcome" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for index, row in theses.iterrows():\n", | ||
" if isinstance(row['results'], list):\n", | ||
" pass\n", | ||
" else:\n", | ||
" uidaho = {YOUR KEY HERE}\n", | ||
" scope = 'ui_alma' #'UI Only'\n", | ||
" title = str(row['title'])\n", | ||
" response = requests.get(f'https://api-na.hosted.exlibrisgroup.com/primo/v1/pnxs?vid=UID&scope={scope}&q=title,contains,\"{title}\",AND&apikey={uidaho}')\n", | ||
" print(response.status_code)\n", | ||
" print(index)\n", | ||
" getOutcome(response.json())\n", | ||
" sleep(0.5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 127, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"setId e5535355c309e64bb69f92dfbe8fe998\n", | ||
"title Ecology of moose on the Copper River Delta, Al...\n", | ||
"results [No Proquest Record Detected, https://uidaho.i...\n", | ||
"Name: 18, dtype: object" | ||
] | ||
}, | ||
"execution_count": 127, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"theses.iloc[18,:]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 128, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for index, row in theses.iterrows():\n", | ||
" for res in row['results']:\n", | ||
" if 'docview' in res:\n", | ||
" theses.at[index, 'results'] = res\n", | ||
" else:\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 129, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"theses.to_csv('./theses/2021-06-28_fishWildAPI.csv', encoding='utf-8')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.9.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"nothing here yet" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"Hello World" |
Oops, something went wrong.