We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 00bfd12 commit 6a78a83Copy full SHA for 6a78a83
0x16-api_advanced/1-main.py
100644
100755
0x16-api_advanced/1-top_ten.py
@@ -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
18
19
+ resp = res.json().get('data').get('children')
20
+ for child in resp:
21
+ print(child.get('data').get('title'))
0 commit comments