Example #1
0
def main():
  # establish db and reddit connections
  db = get_db()
  api = narwal.connect(USERNAME, PASSWORD, user_agent=USER_AGENT)
  
  # given a url, process it.
  # otherwise, process all qualifying iamas on r/iama's frontpage
  if len(sys.argv) == 2:
    # this will actually make an extra request, but oh well.  it's just for
    # testing process_iama() and is not a problem in production
    iama = api.get(relpath(sys.argv[1]))[0][0]
    process_iama(iama, db=db)
  else:
    iamas = [iama for iama in api.hot('iama') if qualifies(iama)]
    log(u'Processing {} IAMAs...'.format(len(iamas)))
    for iama in iamas:
      process_iama(iama, db=db)
    log(u'Processing done.'.encode('utf8'))