def article(self, params):
     """Get the article."""
     article_sid = params.strip()
     log.write("ARTICLE " + article_sid + " BEGIN\n")
     try:
         downloader = ArticleRetriever(article_sid, log=log)
         compressed_article = downloader.getArticleCompressed()
         self._write_to_store(article_sid, compressed_article)
         log.write("ARTICLE " + article_sid + " GOT COMPRESSED DATA\n")
         # Setup upload form and headers
         upload_headers = dict(self.headers)
         form_data = {'article-data' : compressed_article,
                      'article-sid'  : article_sid }
         # Upload the article
         upload_url = self.base_url + '/article/' + article_sid
         response = upload_aux.upload_form(upload_url,
                                           form_data,
                                           upload_headers)
     except NothingForYouToSeeErrorPage:
         log.write( "ARTICLE %s REPORTING NothingForYouToSee error.\n" %\
                         article_sid )
         # FIXME we need to report those pages to the server...
         # Well, for the moment, let's just pretend we didn't see
         # that command...
         req = urllib2.Request(self.base_url + '/nothing-error/' + \
                                 article_sid, headers=self.headers)
         response = urllib2.urlopen(req)
     log.write("ARTICLE " + article_sid + " END\n")
     # Do what the server told us to.
     # Command MUST be SLEEP. We will sleep for at least self.MIN_SLEEP
     command = response.read()
     self._handleCommand(command, do_sleep=True)
Example #2
0
 def article(self, params):
     """Retrieve an article and send it to the server."""
     # Retrieve the article's id and its number of comments
     server_data = params.replace('/', ' ')
     server_data = server_data.strip()
     story_id, total_comments = server_data.split()
     # Download article
     log.write( "ARTICLE " + str(story_id) + " BEGIN\n")
     downloader = ArticleRetriever(story_id, total_comments)
     compressed_article = downloader.get_article_compressed()
     self._write_to_store(story_id, compressed_article)
     log.write( "ARTICLE " + str(story_id) + " GOT COMPRESSED DATA\n")
     # Setup upload form and headers
     upload_headers = dict(self.headers)
     form_data = {'article-data' : compressed_article,
                  'article-sid'  : params,
                  'client-id'    : self.id}
     # Upload the article
     upload_url = self.base_url + '/article/' + params
     response = upload_aux.upload_form(upload_url, form_data, upload_headers)
     log.write( "ARTICLE " + story_id + " END\n")
     # Ok. Command, handled. Now what?
     # Do what the server told us to.
     # Command MUST be SLEEP. We will sleep for at least self.MIN_SLEEP
     command = response.read()
     self._handleCommand(command, do_sleep=True)