-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhackernews.py
More file actions
24 lines (24 loc) · 766 Bytes
/
Copy pathhackernews.py
File metadata and controls
24 lines (24 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests
u = 'https://hacker-news.firebaseio.com/v0/maxitem.json?print=pretty'
response = requests.get(u)
data = response.json()
code = int(data)
u = f'https://hacker-news.firebaseio.com/v0/item/{code}.json?print=pretty'
response = requests.get(u)
story = response.json()
while story['type'] != 'story':
code -= 1
u = f'https://hacker-news.firebaseio.com/fv0/item/{code}.json?print=pretty'
response = requests.get(u)
story = response.json()
url = "No link was given"
by = "No author was given"
title = "No title was given"
for key, item in story.items():
if key == 'title':
title = item
elif key == 'by':
by = item
elif key == 'url':
url = item
print('Title : ', title, '\nAuthor : ', by, "\nLink : ", url)