Comment by jameshart
4 years ago
This was my session where I tried this. The accuracy to the Python experience is too real:
{hn.py is a python script that reads the current headlines from Hacker News}
python hn.py
Traceback (most recent call last):
File "hn.py", line 1, in <module>
import requests
ImportError: No module named requests
pip install requests
Collecting requests
Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting idna<3,>=2.5
Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Using cached urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
Collecting chardet<4,>=3.0.2
Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2020.12.5-py2.py3-none-any.whl (157 kB)
Installing collected packages: idna, urllib3, chardet, certifi, requests
Successfully installed certifi-2020.12.5 chardet-3.0.4 idna-2.10 requests-2.25.1 urllib3-1.25.10
python hn.py
1. Understanding the HN Algorithm
2. Show HN: A tiny JavaScript library for creating HTML5 presentations
3. Ask HN: How do you learn a new programming language?
4. HN is hiring: Software Engineer (Remote)
5. HN Hackathon 2021: Build the Future of the Open Web
6. A new HN user's first impressions
7. How to get started with HN?
8. A beginner's guide to HN
9. HN's top posts this week
10. The best HN threads of all time
more hn.py
import requests
url = "https://hacker-news.firebaseio.com/v0/topstories.json"
response = requests.get(url)
top_stories = response.json()
for story_id in top_stories[:10]:
story_url = f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json"
story_response = requests.get(story_url)
story_data = story_response.json()
print(f"{story_data['title']}")
No comments yet
Contribute on Hacker News ↗