Esempio n. 1
0
def main():
    """ Retrieve and store all new tweets from the user home timeline.
    """
    # Logger
    logger = log.file_console_log()

    # Connect to the MongoDB database
    stored_tweets = db.twitter_collection()

    # Retrieve tweets from user timeline and store new ones in database
    # If any error occurs, log it in log file
    try:
        timeline_tweets = twitter.home_timeline()
    except Exception, error:
        logger.error(traceback.format_exc()[:-1])  # log error
        raise error
 def test_tweet_structure(self):
     """ Test the structure of a tweet (stored as a Python dictionary).
         Ensure that all mandatory keys are presents.
     """
     tweet = twitter.home_timeline(count=1)[0]
     self.assertTrue("source" in tweet)
     self.assertNotEqual(tweet['source'], '')
     self.assertTrue("source_url" in tweet)
     self.assertNotEqual(tweet['source_url'], '')
     self.assertTrue("author" in tweet)
     self.assertNotEqual(tweet['author'], '')
     self.assertTrue("text" in tweet)
     self.assertNotEqual(tweet['text'], '')
     self.assertTrue("truncated" in tweet)
     self.assertTrue("hashtags" in tweet)
     self.assertTrue("_id" in tweet)
     assert tweet['_id'] is not None
 def test_tweet_structure(self):
     """ Test the structure of a tweet (stored as a Python dictionary).
         Ensure that all mandatory keys are presents.
     """
     tweet = twitter.home_timeline(count=1)[0]
     self.assertTrue("source" in tweet)
     self.assertNotEqual(tweet['source'], '')
     self.assertTrue("source_url" in tweet)
     self.assertNotEqual(tweet['source_url'], '')
     self.assertTrue("author" in tweet)
     self.assertNotEqual(tweet['author'], '')
     self.assertTrue("text" in tweet)
     self.assertNotEqual(tweet['text'], '')
     self.assertTrue("truncated" in tweet)
     self.assertTrue("hashtags" in tweet)
     self.assertTrue("_id" in tweet)
     assert tweet['_id'] is not None
 def test_insertion_mongo(self):
     """ Tests that fetched tweets are correclty inserted in mongo. """
     timeline = twitter.home_timeline()
     for tweet in timeline:
         db.insert(tweet, self.tweets_collection)
     self.assertEqual(db.size(self.tweets_collection), len(timeline))
 def test_home_timeline(self):
     """ Test that the `twitter.API.home_timeline` returns the expected
         number of tweets.
     """
     timeline = twitter.home_timeline(count=2)
     self.assertEqual(len(timeline), 2)
 def test_insertion_mongo(self):
     """ Tests that fetched tweets are correclty inserted in mongo. """
     timeline = twitter.home_timeline()
     for tweet in timeline:
         db.insert(tweet, self.tweets_collection)
     self.assertEqual(db.size(self.tweets_collection), len(timeline))
 def test_home_timeline(self):
     """ Test that the `twitter.API.home_timeline` returns the expected
         number of tweets.
     """
     timeline = twitter.home_timeline(count=2)
     self.assertEqual(len(timeline), 2)