File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/python3
2+ """add to a list of hot list"""
3+ import requests
4+
5+
6+ def recurse (subreddit , hot_list = [], after = "" , count = 0 ):
7+ """recurse the value"""
8+ params = {
9+ 'after' : after ,
10+ 'count' : count ,
11+ 'limit' : 100
12+ }
13+ headers = {'User-Agent' : 'Alx Task' }
14+ url = 'http://www.reddit.com/r/{}/top/.json' .format (subreddit )
15+ res = requests .get (url , params = params ,
16+ headers = headers )
17+ if res .status_code >= 400 :
18+ return None
19+ result = res .json ().get ('data' )
20+ after = result .get ('after' )
21+ count += result .get ('dist' )
22+ resp = result .get ('children' )
23+ for child in resp :
24+ hot_list .append (child .get ('data' ).get ('title' ))
25+ if after is not None :
26+ return recurse (subreddit , hot_list , after , count )
27+ else :
28+ return hot_list
You can’t perform that action at this time.
0 commit comments