You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/reading.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1431,19 +1431,25 @@ responds to your request with some text:
1431
1431
{"date":"2023-07-13","explanation":"A mere 390 light-years away, Sun-like stars and future planetary systems are forming in the Rho Ophiuchi molecular cloud complex, the closest star-forming region to our fair planet. The James Webb Space Telescope's NIRCam peered into the nearby natal chaos to capture this infrared image at an inspiring scale. The spectacular cosmic snapshot was released to celebrate the successful first year of Webb's exploration of the Universe. The frame spans less than a light-year across the Rho Ophiuchi region and contains about 50 young stars. Brighter stars clearly sport Webb's characteristic pattern of diffraction spikes. Huge jets of shocked molecular hydrogen blasting from newborn stars are red in the image, with the large, yellowish dusty cavity carved out by the energetic young star near its center. Near some stars in the stunning image are shadows cast by their protoplanetary disks.","hdurl":"https://apod.nasa.gov/apod/image/2307/STScI-01_RhoOph.png","media_type":"image","service_version":"v1","title":"Webb's Rho Ophiuchi","url":"https://apod.nasa.gov/apod/image/2307/STScI-01_RhoOph1024.png"}
1432
1432
```
1433
1433
1434
-
Woah! What a mess! There is definitely some data there, but it's a bit hard to see what it all is. As it turns out, this is a common format for data called *JSON* (JavaScript Object Notation). You can
1435
-
interpret this data just like you'd interpret a Python dictionary: these are `key : value` pairs separated by commas. For example, if you look closely, you'll see that the first entry is
1436
-
`"date":"2023-07-13"`, which indicates that we indeed successfully received data corresponding to July 13, 2023.
1437
-
1438
-
So now the job is to do all of this programmatically in Python. We will load the `requests` package to make the query, and the `json` package to interpret the JSON response.
1439
-
You will recognize the same query URL we pasted into the browser below as well.
1434
+
Woah! What a mess! There is definitely some data there, but it's a bit hard to
1435
+
see what it all is. As it turns out, this is a common format for data called
1436
+
*JSON* (JavaScript Object Notation). You can interpret this data just like
1437
+
you'd interpret a Python dictionary: these are `key : value` pairs separated by
1438
+
commas. For example, if you look closely, you'll see that the first entry is
1439
+
`"date":"2023-07-13"`, which indicates that we indeed successfully received
1440
+
data corresponding to July 13, 2023.
1441
+
1442
+
So now the job is to do all of this programmatically in Python. We will load
1443
+
the `requests` package, and make the query using the `get` function, which takes a single URL argument;
1444
+
you will recognize the same query URL that we pasted into the browser earlier below.
1445
+
We will then name the response object `nasa_response`, and obtain a JSON representation using the `json` method.
1446
+
Finally, we use the `dumps` method from the `json` package to obtain the response as a nicely-formatted string object.
0 commit comments