def test_parse_tweet_from_url(self):
	''' Tests that tweet from hashtag can be parsed to correct text '''
	tweets = get_fewer_tweets_from_hashtag(connect(), "#musicthatdontmatch")
	parsed_tweets = parse_all(tweets)
	tweet = parsed_tweets[0]
	text = get_tweet_from_url(connect(), tweet['url'])
	self.assertEqual(parse(text)['line'], tweet['line'])
    def test_couplet_urls(self):
	''' Tests that couplet returns poem and corresponding url '''
	couplet = generatePoem("#NationalPetDay", 'couplet')
	lines = couplet.split('\n')
	text0 = get_tweet_from_url(connect(), lines[2])
	text1 = get_tweet_from_url(connect(), lines[3])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
    def test_haiku_urls(self):
	''' Tests that haiku returns poem and corresponding url '''
	haiku = generatePoem("#NationalPetDay", 'haiku')
	lines = haiku.split('\n')
	text0 = get_tweet_from_url(connect(), lines[3])
	text1 = get_tweet_from_url(connect(), lines[4])
	text2 = get_tweet_from_url(connect(), lines[5])
	self.assertEqual(parse(text0)['line'], lines[0])
	self.assertEqual(parse(text1)['line'], lines[1])
	self.assertEqual(parse(text2)['line'], lines[2])
 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))
 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))
 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")
 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)
示例#8
0
def home_page():
    """This is the home page of the site, containing topics.
    Topics are refreshed every 20 seconds.
    """
    try:
        diff = datetime.datetime.now() - session["lastUpdateTime"]
        if diff.total_seconds() > 20:
            twitter = connect()
            session["trending"] = get_trending_topics(twitter)
            session["lastUpdateTime"] = datetime.datetime.now()
    except KeyError:
        twitter = connect()
        session["trending"] = get_trending_topics(twitter)
        session["lastUpdateTime"] = datetime.datetime.now()
    top_poems = Poem.query.order_by(Poem.likes.desc()).all()
    recent_poems = Poem.query.order_by(Poem.date.desc()).all()
    return render_template("index.html", trending=session["trending"], recent=recent_poems[:5], top=top_poems[:5])
 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")
 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)
示例#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()
    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.")
 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)
 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.")
 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)
示例#16
0
def sendtweet():
    """request to submit a generated poem to twitter"""
    print "sending tweet"
    print request.form["id"]
    twitter = connect()
    poem = Poem.query.filter_by(id=request.form["id"]).first()
    if poem is None:
    	abort(404)
    sendPoem(twitter, poem)
    print "send success"
    return redirect(url_for("poem", id=str(poem.id)))
示例#17
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()
示例#18
0
    def test_url_returns_correct_tweet(self):
	''' Tests that tweet matches url '''
	self.assertEqual(get_tweet_from_url(connect(), "https://twitter.com/mrssmallwood/status/454661604014305280"), "Today is #NationalSiblingsDay @andrew_pozzi @beckypozzi @jamespozzi @chrispozzi @RichPozzi aren't we lucky ;)")
示例#19
0
    def test_hashtag_urls(self):
	''' Tests that tweet gotten from hashtag search matches url '''
	tweets = get_fewer_tweets_from_hashtag(connect(), "#BatonRougeSlang")
	self.assertEqual(get_tweet_from_url(connect(), tweets[1]), tweets[0])