def fetch_listing(path, limit=1000, batch_size=100):
 session = requests.Session()
 session.headers.update({'User-Agent': 'reddit-test-data-generator/1.0'})
 base_url = ('https://api.reddit.com' + path)
 after = None
 count = 0
 while (count < limit):
  params = {'limit': batch_size, 'count': count}
  if after:
   params['after'] = after
  print '> {}-{}'.format(count, (count + batch_size))
  response = session.get(base_url, params=params)
  response.raise_for_status()
  listing = get_requests_resp_json(response)['data']
  for child in listing['children']:
   (yield child['data'])
   count += 1
  after = listing['after']
  if (not after):
   break
  time.sleep(2)

def fetch_listing ( path , limit = 1000 , batch_size = 100 ) : session = requests . Session ( ) session . headers . update ( { 'User-Agent' : 'reddit-test-data-generator/1.0' } ) base_url = ( 'https://api.reddit.com' + path ) after = None count = 0 while ( count < limit ) : params = { 'limit' : batch_size , 'count' : count } if after : params [ 'after' ] = after print '> {}-{}' . format ( count , ( count + batch_size ) ) response = session . get ( base_url , params = params ) response . raise_for_status ( ) listing = get_requests_resp_json ( response ) [ 'data' ] for child in listing [ 'children' ] : ( yield child [ 'data' ] ) count += 1 after = listing [ 'after' ] if ( not after ) : break time . sleep ( 2 )
fetch a reddit listing from reddit .