Skip to content

Commit

Permalink
adding exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
mcburton committed Mar 17, 2021
1 parent 79f8896 commit 9ee246f
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions week-9-exercises.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Request API Key"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q1** The Digital Public Library of America (DPLA) has an API that allows you to programmatically access information about their collection. In order to access their API, you must have an *API KEY*. Read the [DPLA Developers Policy on API keys](https://pro.dp.la/developers/policies#get-a-key) for instructions on how to request an API key. In this exercise, you are going to use Python to *request* an API key to be sent to your email address. You will use this API key in Q2.\n",
"\n",
"Steps for accessing the DPLA API:\n",
"1. Review the [DPLA Documentation](https://pro.dp.la/developers/policies#get-a-key) \n",
"2. Using the `requests` Python library, make an appropirate HTTP request type to the proper URL.\n",
" * Review the [Requests](https://requests.readthedocs.io/en/master/user/quickstart/) library for how to make different kinds of requests.\n",
"3. Print the response received from the request.\n",
"4. Check your email to see if you got an API key. It should be a long string of characters and numbers that looks like `389fecd655b4c95532179f4337e50c84`\n",
" \n",
"**Hint** Pay attention to the HTTP request METHOD and make sure to include your email in the appropriate part of the URL."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# importing the requests library\n",
"import requests\n",
"\n",
"# your code here\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Parse the Request Results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Q2** \n",
"\n",
"In this question, you are going to use the API key you created in question 1 to search the library using Python. Read the DPLA documentation on [API Basics](https://pro.dp.la/developers/api-basics), [making requests](https://pro.dp.la/developers/requests), and what [responses look like](https://pro.dp.la/developers/responses). Reading documentation is crucial for using APIs because they provide the instructions for how to access the API and the shape of the data you will get in response. \n",
"\n",
"Using the `requests` python library, make a request for *items* that match the following:\n",
"\n",
"* Items with the key word \"pittsburgh\"\n",
"* Published after 2010 \n",
"* Published before 2020\n",
" \n",
"Think about the URL for searching *items* and the HTTP parameters for the query. Refer to the [simple search](https://pro.dp.la/developers/requests#simple) and [temporal search](https://pro.dp.la/developers/requests#temporal) documentation for helping.\n",
" \n",
" \n",
"The results will include a TON of information. Refer to the DPLA's [Object Structure](https://pro.dp.la/developers/object-structure) documentation to see a human readable represntation of the results. To make things simple, lets just print the [`isShownAt`](https://pro.dp.la/developers/field-reference#isShownAt) field for each of the results. This means reaching into the response JSON, finding the list of results, and looping over just those pieces of data. This will be a list of URLs that you can visit to see the items in their home collections.\n",
"\n",
"The output should look like:\n",
"```\n",
"http://name.umdl.umich.edu/IC-LBC2IC-X-SCLP1905%5DSCLP_1905\n",
"http://cdm17191.contentdm.oclc.org/cdm/ref/collection/arc5100/id/246\n",
"https://utah-primoprod.hosted.exlibrisgroup.com/primo-explore/fulldisplay?docid=digcoll_usu_16Design/2653&context=L&vid=MWDL\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/53067\n",
"http://historicpittsburgh.org/islandora/object/pitt%3A00ajs9834m\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/41703\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/34443\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/53026\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/50111\n",
"http://digitalcollections.powerlibrary.org/cdm/ref/collection/pcalo-ishc/id/30527\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n"
]
}
],
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 9ee246f

Please sign in to comment.