Skip to content

Commit a7b38fa

Browse files
mlee comments addressed
1 parent c1985de commit a7b38fa

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed
-24.5 KB
Loading

source/reading.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ something known as an **a**pplication **p**rogramming **i**nterface (API),
961961
which provides a programmatic way to ask for subsets of a data set. This allows
962962
the website owner to control *who* has access to the data, *what portion* of
963963
the data they have access to, and *how much* data they can access. Typically,
964-
the website owner will give you a *token* (or *key*, a secret string of characters
964+
the website owner will give you a *token* or *key* (a secret string of characters
965965
somewhat like a password) that you have to provide when accessing the API.
966966

967967
```{index} web scraping, CSS, HTML
@@ -1069,7 +1069,7 @@ above you can see a line that looks like
10691069
<span class="result-price">$800</span>
10701070
```
10711071

1072-
That is definitely storing the price of a particular apartment. With some more
1072+
That snippet is definitely storing the price of a particular apartment. With some more
10731073
investigation, you should be able to find things like the date and time of the
10741074
listing, the address of the listing, and more. So this source code most likely
10751075
contains all the information we are interested in!
@@ -1152,7 +1152,7 @@ The selector gadget returns them to us as a comma-separated list (here
11521152
`.housing , .result-price`), which is exactly the format we need to provide to
11531153
Python if we are using more than one CSS selector.
11541154

1155-
**Stop! Are you allowed to scrape that website?**
1155+
**Caution: are you allowed to scrape that website?**
11561156

11571157
```{index} web scraping; permission
11581158
```
@@ -1336,7 +1336,7 @@ format for data analysis.
13361336

13371337
Rather than posting a data file at a URL for you to download, many websites
13381338
these days provide an API that can be accessed through a programming language
1339-
like Python. The benefit of this is that data owners have much more control
1339+
like Python. The benefit of using an API is that data owners have much more control
13401340
over the data they provide to users. However, unlike web scraping, there is no
13411341
consistent way to access an API across websites. Every website typically has
13421342
its own API designed especially for its own use case. Therefore we will just
@@ -1359,7 +1359,7 @@ The James Webb Space Telescope's NIRCam image of the Rho Ophiuchi molecular clou
13591359

13601360
+++
13611361

1362-
First, you will need to visit the [NASA APIs page](https://api.nasa.gov/) and generate an API key.
1362+
First, you will need to visit the [NASA APIs page](https://api.nasa.gov/) and generate an API key (i.e., a password used to identify you when accessing the API).
13631363
Note that a valid email address is required to
13641364
associate with the key. The signup form looks something like {numref}`fig:NASA-API-signup`.
13651365
After filling out the basic information, you will receive the token via email.
@@ -1372,7 +1372,7 @@ Make sure to store the key in a safe place, and keep it private.
13721372
Generating the API access token for the NASA API.
13731373
```
13741374

1375-
**Stop! Think about your API usage carefully!**
1375+
**Caution: think about your API usage carefully!**
13761376

13771377
When you access an API, you are initiating a transfer of data from a web server
13781378
to your computer. Web servers are expensive to run and do not have infinite resources.
@@ -1407,8 +1407,7 @@ API, we need to specify three things. First, we specify the URL *endpoint* of
14071407
the API, which is simply a URL that helps the remote server understand which
14081408
API you are trying to access. NASA offers a variety of APIs, each with its own
14091409
endpoint; in the case of the NASA "Astronomy Picture of the Day" API, the URL
1410-
endpoint is `https://api.nasa.gov/planetary/apod`, as shown at the top of
1411-
{numref}`fig:NASA-API-parameters`. Second, we write `?`, which denotes that a
1410+
endpoint is `https://api.nasa.gov/planetary/apod`. Second, we write `?`, which denotes that a
14121411
list of *query parameters* will follow. And finally, we specify a list of
14131412
query parameters of the form `parameter=value`, separated by `&` characters. The NASA
14141413
"Astronomy Picture of the Day" API accepts the parameters shown in
@@ -1423,7 +1422,8 @@ along with syntax, default settings, and a description of each.
14231422

14241423
So for example, to obtain the image of the day
14251424
from July 13, 2023, the API query would have two parameters: `api_key=YOUR_API_KEY`
1426-
and `date=2023-07-13`.
1425+
and `date=2023-07-13`. Remember to replace `YOUR_API_KEY` with the API key you
1426+
received from NASA in your email! Putting it all together, the query will look like the following:
14271427
```
14281428
https://api.nasa.gov/planetary/apod?api_key=YOUR_API_KEY&date=2023-07-13
14291429
```
@@ -1457,20 +1457,21 @@ commas. For example, if you look closely, you'll see that the first entry is
14571457
`"date":"2023-07-13"`, which indicates that we indeed successfully received
14581458
data corresponding to July 13, 2023.
14591459

1460-
So now the job is to do all of this programmatically in Python. We will load
1460+
So now our job is to do all of this programmatically in Python. We will load
14611461
the `requests` package, and make the query using the `get` function, which takes a single URL argument;
14621462
you will recognize the same query URL that we pasted into the browser earlier.
1463-
We will then name the response object `nasa_data`, and obtain a JSON representation of the
1463+
We will then obtain a JSON representation of the
14641464
response using the `json` method.
14651465

14661466
<!-- we have disabled the below code for reproducibility, with hidden setting
14671467
of the nasa_data object. But you can reproduce this using the DEMO_KEY key -->
14681468
```python
14691469
import requests
14701470

1471-
requests.get(
1471+
nasa_data_single = requests.get(
14721472
"https://api.nasa.gov/planetary/apod?api_key=YOUR_API_KEY&date=2023-07-13"
14731473
).json()
1474+
nasa_data_single
14741475
```
14751476

14761477
```{code-cell} ipython3
@@ -1486,8 +1487,8 @@ We can obtain more records at once by using the `start_date` and `end_date` para
14861487
shown in the table of parameters in {numref}`fig:NASA-API-parameters`.
14871488
Let's obtain all the records between May 1, 2023, and July 13, 2023, and store the result
14881489
in an object called `nasa_data`; now the response
1489-
will take the form of a Python list, with one dictionary item similar to the above
1490-
for each of the 74 days between the start and end dates:
1490+
will take the form of a Python list. Each item in the list will correspond to a single day's record (just like the `nasa_data_single` object),
1491+
and there will be 74 items total, one for each day between the start and end dates:
14911492

14921493
```python
14931494
nasa_data = requests.get(

0 commit comments

Comments
 (0)