コード例 #1
0
 def test_throws_exception(self):
     ''' Tests that an exception is thrown when the rate limit has been hit  '''
     twitter = connect()
     print remaining
     for i in range(0, remaining):
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     with self.assertRaises(Exception):
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
コード例 #2
0
 def test_exception_format(self):
     ''' Tests that the exception message has the correct format  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         self.assertTrue("You hit the rate limit! Try again in " in str(e))
         self.assertTrue(" seconds." in str(e))
コード例 #3
0
 def test_exception_decreases(self):
     ''' Tests that the exception message decreases  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         s = str(e)
         self.assertTrue(float(s[s.index("in")+6:s.index("seconds")-1])<num)
コード例 #4
0
 def test_exception_format(self):
     ''' Tests that the exception message has the correct format  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         self.assertTrue("You hit the rate limit! Try again in " in str(e))
         self.assertTrue(" seconds." in str(e))
コード例 #5
0
 def test_throws_exception(self):
     ''' Tests that an exception is thrown when the rate limit has been hit  '''
     twitter = connect()
     print remaining
     for i in range(0,remaining):
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     with self.assertRaises(Exception):
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
コード例 #6
0
 def test_exception_decreases(self):
     ''' Tests that the exception message decreases  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         s = str(e)
         self.assertTrue(
             float(s[s.index("in") + 6:s.index("seconds") - 1]) < num)
コード例 #7
0
    def test_no_exception(self):
        ''' Tests that an exception isn't thrown when the rate limit hasn't been hit '''
        twitter = connect()
        try:
            get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
            global remaining
            remaining = get_remaining_api_calls(twitter)

        except:
            self.fail("Exception was thrown where one wasn't expected.")
コード例 #8
0
 def test_exception_less_than_15_minutes(self):
     ''' Tests that an exception says the remaining seconds and that it's less than 15 minutes  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         s = str(e)
         global num
         num = float(s[s.index("in") + 6:s.index("seconds") - 1])
         self.assertTrue(num < 15 * 60)
コード例 #9
0
 def test_no_exception(self):
     ''' Tests that an exception isn't thrown when the rate limit hasn't been hit '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
         global remaining
         remaining = get_remaining_api_calls(twitter)
     
     except:
         self.fail("Exception was thrown where one wasn't expected.")
コード例 #10
0
 def test_exception_less_than_15_minutes(self):
     ''' Tests that an exception says the remaining seconds and that it's less than 15 minutes  '''
     twitter = connect()
     try:
         get_tweets_from_hashtag(twitter, "#WeWereBornForThis")
     except Exception as e:
         s = str(e)
         global num
         num = float(s[s.index("in")+6:s.index("seconds")-1])
         self.assertTrue(num<15*60)
コード例 #11
0
def load_more_tweets(hashtag, tries=10, count=100):
    ''' Loads a maximum of count * tries number of new recent tweets with the given hashtag into the database '''
    
    twitter = connect()
    tweets = get_tweets_from_hashtag(twitter, hashtag, tries=tries, count=count)
    parsed_tweets = parse_all(tweets, hashtag)
    inserter = Tweet.__table__.insert().prefix_with('IGNORE')
    engine.execute(inserter, parsed_tweets)
    db.session.commit()
コード例 #12
0
def load_more_tweets(hashtag, tries=10, count=100):
    ''' Loads a maximum of count * tries number of new recent tweets with the given hashtag into the database '''

    twitter = connect()
    tweets = get_tweets_from_hashtag(twitter,
                                     hashtag,
                                     tries=tries,
                                     count=count)
    parsed_tweets = parse_all(tweets, hashtag)
    inserter = Tweet.__table__.insert().prefix_with('IGNORE')
    engine.execute(inserter, parsed_tweets)
    db.session.commit()