Exemplo n.º 1
0
  def run(self):
    for (article_id, raw_tex) in rssparse(arxiv_feed_url, self.last_parsed_id):
      if self.terminate_request_flag:
        critical("Worker thread caught terminate_request_flag, terminating")
        self.terminate()
        return
      
      self.last_parsed_id = article_id

      logging.info("Attempting raw tex from article_id: "+ str(article_id))
      
      if not raw_tex:
        error("Got empty raw_tex from article_id: " + str(article_id))
        continue
      
      haiku_list = []
      try:
        raw_text = self.untex_thread_class.run_untex(raw_tex)
        haiku_list = self.haiku_finder.find_haiku_in_text(raw_text)
      except RuntimeError as e:
        print_with_warning(str(e))
      if len(haiku_list)==0:
        logging.info("Found no Haiku in article_id: " + str(article_id))
      else:
        for haiku in haiku_list:
          self.results_queue.put(haiku + " (" + str(article_id) + ") #arXivHaiku")
          logging.info("Found haiku in article_id :" + str(article_id) + " : " + haiku)
    print_with_ok("Got to the end of the list :(")
    logging.info("Worker thread finished")
    self.terminate()
Exemplo n.º 2
0
    )
    return (resp,content)

#Post status to twitter, returns tuple of (success, error_message)
def post_status_to_twitter(status):
  logging.info("Attempting to tweet: "+status)
  content = oauth2_request(
    'https://api.twitter.com/1.1/statuses/update.json',
    app_token,
    app_token_secret,
    http_method="POST",
    post_body="status="+htmlescape(status),
    )
  if content[0]['status'] != '200':
    logging.warning("Tweet unsuccessful.  Error message: " + str(content))
    return (False, content)
  logging.info("Tweet successful.")
  return (True, None)

if __name__ == "__main__":
  logging.basicConfig(filename="../logs/twitter.log", level=logging.DEBUG)
  
  print "Testing by posting twice to twitter, the first should succeed and the second fail for posting same status twice.\n"
  (success1, error1) = post_status_to_twitter("Blah Blah Haiku")
  (success2, error2) = post_status_to_twitter("Blah Blah Haiku")
  if success1 and not success2: 
    print_with_ok("Test Successful\n")
  else: 
    print_with_fail("Test Unsuccessful\n")
  print_with_warning("You need to delete the last post off twitter now...\n")
Exemplo n.º 3
0
def error(msg):
  logging.error(msg)
  print_with_warning(msg)