Example #1
0
 def test_fetch_timeline_empty(self):
     fetcher.fetch_url = Mock()
     fetcher.fetch_url.return_value = [None, [], MSG_OK, 0]
     assert (MSG_OK, [], 0) == fetch_timeline(user_id=22)
     fetcher.fetch_url.assert_called_with(
         'get',
         'http://api.twitter.com/1/statuses/user_timeline.json?count=200&include_rts=1&include_entities=1&user_id=22'
     )
Example #2
0
    try:
        abort = (writer.get_total() == 0)
        first_tweet = writer.get_first()
        since_id = int(first_tweet['id_str'])
    except Exception, exc:
        abort = True

    if abort:
        log.msg("Timeline file for user_id %d is not present. Bogus data?" %
                user_id)

        # Let's treat this as not found user
        return TwitterResponse(STATUS_UNAUTHORIZED, user_id, 0, 0)

    msg, timeline, sleep_time = fetch_timeline(user_id=user_id,
                                               since_id=since_id)

    if len(timeline) > 0 and msg == MSG_OK:
        # Here we need to create a new file containing the delta timeline
        # and also include the previous tweets

        total_included = 0
        total_fetched = len(timeline)

        for tweet in timeline:
            if must_include(tweet):
                writer.add_tweet(tweet)
                total_included += 1

        response = TwitterResponse(TwitterResponse.msg_to_status(msg), user_id,
                                   0, sleep_time)
Example #3
0
 def test_fetch_timeline_empty(self):
     fetcher.fetch_url = Mock()
     fetcher.fetch_url.return_value = [None, [], MSG_OK, 0]
     assert (MSG_OK, [], 0) == fetch_timeline(user_id=22)
     fetcher.fetch_url.assert_called_with('get', 'http://api.twitter.com/1/statuses/user_timeline.json?count=200&include_rts=1&include_entities=1&user_id=22')
Example #4
0
    abort = False

    try:
        abort = (writer.get_total() == 0)
        first_tweet = writer.get_first()
        since_id = int(first_tweet['id_str'])
    except Exception, exc:
        abort = True

    if abort:
        log.msg("Timeline file for user_id %d is not present. Bogus data?" % user_id)

        # Let's treat this as not found user
        return TwitterResponse(STATUS_UNAUTHORIZED, user_id, 0, 0)

    msg, timeline, sleep_time = fetch_timeline(user_id=user_id, since_id=since_id)

    if len(timeline) > 0 and msg == MSG_OK:
        # Here we need to create a new file containing the delta timeline
        # and also include the previous tweets

        total_included = 0
        total_fetched = len(timeline)

        for tweet in timeline:
            if must_include(tweet):
                writer.add_tweet(tweet)
                total_included += 1

        response = TwitterResponse(TwitterResponse.msg_to_status(msg),
            user_id,