-
Notifications
You must be signed in to change notification settings - Fork 1
/
news.py
37 lines (23 loc) · 906 Bytes
/
news.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
import json
from decouple import config
url = "https://community-hacker-news-v1.p.rapidapi.com/topstories.json"
querystring = {"print":"pretty"}
headers = {
'x-rapidapi-key': config("HN_RAPID_API_KEY"),
'x-rapidapi-host': "community-hacker-news-v1.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring).json()
def item(url):
#"https://community-hacker-news-v1.p.rapidapi.com/item/8863.json"
itemurl = url
querystring = {"print":"pretty"}
headers = {
'x-rapidapi-key': config("HN_RAPID_API_KEY"),
'x-rapidapi-host': "community-hacker-news-v1.p.rapidapi.com"
}
itemresponse = requests.request("GET", itemurl, headers=headers, params=querystring)
print(itemresponse.text)
for i in range(50):
itemurl = ("https://community-hacker-news-v1.p.rapidapi.com/item/" + str(response[i]) + ".json")
item(itemurl)