0

I'm trying to use the Python-Twitter library (https://github.com/bear/python-twitter) to extract mentions of a twitter account using the GetMention() function. The script populates a database and runs periodically on a cron job so I don't want to extract every mention, only those since the last time the script was run.

The code below extracts the mentions fine but for some reason the 'since_id' argument doesn't seem to do anything - the function returns all the mentions every time I run it, rather than filtering for only the most recent mentions. For reference the documentation is here: https://python-twitter.googlecode.com/hg/doc/twitter.html#Api-GetMentions)

What is the correct way to implement the GetMention() function? (I've looked but I can't find any examples online). Alternatively, is there a different/more elegant way of extracting twitter mentions that I'm overlooking?

def scan_timeline():
''' Scans the timeline and populates the database with the results '''

    FN_NAME = "scan_timeline"

    # Establish the api connection
    api = twitter.Api(
                  consumer_key = "consumerkey",
                  consumer_secret = "consumersecret",
                  access_token_key = "accesskey",
                  access_token_secret = "accesssecret"
                  )


    # Tweet ID of most recent mention from the last time the function was run
    # (In actual code this is dynamic and extracted from a database)
    since_id = 498404931028938752

    # Retrieve all mentions created since the last scan of the timeline
    length_of_response = 20
    page_number = 0

    while length_of_response == 20:

        # Retreive most recent mentions
        results = api.GetMentions(since_id,None,page_number)


    ### Additional code inserts the tweets into a database ###
AdamDynamic
  • 761
  • 6
  • 15
  • 29

1 Answers1

0

Your syntax seems to be consistent as per mentioned in the Python-Twitter library. What I think is happening is the following:

If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.

Which would lead to all the tweets starting from the oldest available ID. Try working with a more recent since ID value. Equivalently, also check whether the since ID you're giving is appropriate or not.

sgp
  • 1,738
  • 6
  • 17
  • 31
  • I'm confident that the ID I'm supplying is correct - I saw the 'limit of Tweets' line in the documentation but wasn't sure which 'limit' it referred to? (Limit of calls to the api? Limit of tweets returned by the function?) Odd that it doesn't seem to work, thanks for the help though! – AdamDynamic Aug 17 '14 at 15:00