The readings for Tuesday, November 01 are:
Python for Informatics: Exploring Information
Chapter 13. Using Web Services
You only need to read sections 13.4, 13.5, and 13.6
Requests should already be installed, so you can skip any instructions about installing it.
Once you have completed these readings, please answer the following questions:
What are some advantages to using the csv Python module for parsing comma-separated-values, rather than simplying doing str.split?
Use Requests to fetch JSON data from your favorite subreddit:
# Fetch data from r/Python subreddit
import requests
response = requests.get('https://reddit.com/r/Python/.json')
a. How do you access the text of the response
?
b. How do you access the JSON of the response
?
c. Explore the JSON data. Write a code snippet that prints out the title of the subreddit post with the highest score.
Note: If your response
object is something like {'error': 429}
, then
reddit thinks you are making too many requests. We can try to trick the
website by faking the user-agent
as follows:
import requests
headers = {'user-agent': 'my-python-request'}
response = requests.get('https://reddit.com/r/Python/.json', headers=headers)
If you have any questions, comments, or concerns regarding the course, please provide your feedback here.
To submit your response, please edit the reading08/README.md file in your GitLab repository.