Skip to content

Commit 6a78a83

Browse files
Top Ten
1 parent 00bfd12 commit 6a78a83

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

0x16-api_advanced/1-main.py

100644100755
File mode changed.

0x16-api_advanced/1-top_ten.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/python3
2+
"""gets the top ten subbredit api"""
3+
import requests
4+
5+
6+
def top_ten(subreddit):
7+
"""lists top 10 reddit api"""
8+
if subreddit is None or type(subreddit) != str:
9+
print('None')
10+
return
11+
params = {'limit': 10}
12+
headers = {'User-Agent': 'Reddit apI'}
13+
url = "http://www.reddit.com/r/{}/top/.json".format(subreddit)
14+
res = requests.get(url, params=params,
15+
headers=headers)
16+
if res.status_code != 200:
17+
print('None')
18+
return
19+
resp = res.json().get('data').get('children')
20+
for child in resp:
21+
print(child.get('data').get('title'))

0 commit comments

Comments
 (0)