コード例 #1
0
def get_tweets():
    """Fetches up to 10 tweets and returns their text in a list"""
    hashtag = "maker"

    sources = []
    try:
        tso = TwitterSearchOrder()
        tso.setSearchURL("?q=%23" + hashtag)
        tso.setLocale('en')
        tso.setCount(10)
        tso.setIncludeEntities(False)

        twitter_search = TwitterSearch(
            consumer_key = Secrets.consumer_key,
            consumer_secret = Secrets.consumer_secret,
            access_token = Secrets.access_token,
            access_token_secret = Secrets.access_token_secret
            )

        tweets = twitter_search.searchTweets(tso)

        for tweet in tweets['content']['statuses']:
            sources.append(tweet['text'])

    except TwitterSearchException as exception:
        print(exception)

    return sources
コード例 #2
0
def get_tweets():
    """Fetches up to 10 tweets and returns their text in a list"""
    hashtag = "maker"

    sources = []
    try:
        tso = TwitterSearchOrder()
        tso.setSearchURL("?q=%23" + hashtag)
        tso.setLocale('en')
        tso.setCount(10)
        tso.setIncludeEntities(False)

        twitter_search = TwitterSearch(
            consumer_key=Secrets.consumer_key,
            consumer_secret=Secrets.consumer_secret,
            access_token=Secrets.access_token,
            access_token_secret=Secrets.access_token_secret)

        tweets = twitter_search.searchTweets(tso)

        for tweet in tweets['content']['statuses']:
            sources.append(tweet['text'])

    except TwitterSearchException as exception:
        print(exception)

    return sources
コード例 #3
0
ファイル: blha.py プロジェクト: rharige/GrepTwitter
    tso.setCount(100)
    tso.setKeywords(['ireland'])

    ts = TwitterSearch(config.get('twitter_keys', 'consumer_key'), config.get('twitter_keys', 'consumer_secret'),
                       config.get('twitter_keys', 'access_token'),
                       config.get('twitter_keys', 'access_token_secret'))

    # init variables needed in loop
    todo = True
    next_max_id = 0

    # let's start the action
    while todo:

        # first query the Twitter API
        response = ts.searchTweets(tso)

        # print rate limiting status
        print "Current rate-limiting status: %s" % ts.getMetadata()['x-rate-limit-remaining']

        # check if there are statuses returned and whether we still have work to do
        todo = not len(response['content']['statuses']) == 0

        # check all tweets according to their ID
        for tweet in response['content']['statuses']:
            tweet_id = tweet['id']
            # print("Seen tweet with ID %i" % tweet_id)

            # current ID is lower than current next_max_id?
            if (tweet_id < next_max_id) or (next_max_id == 0):
                next_max_id = tweet_id
コード例 #4
0
ファイル: test.py プロジェクト: correnm/cs595-f13
    ts = TwitterSearch(
        consumer_key='LrA1DdH1QJ5cfS8gGaWp0A',
        consumer_secret='9AX14EQBLjRjJM4ZHt2kNf0I4G77sKsYX1bEXQCW8',
        access_token='1862092890-FrKbhD7ngeJtTZFZwf2SMjOPwgsCToq2A451iWi',
        access_token_secret='AdMQmyfaxollI596G82FBipfSMhagv6hjlNKoLYjeg8')

    # init variables needed in loop
    todo = True
    next_max_id = 0

    # let's start the action
    while (todo):

        # first query the Twitter API
        response = ts.searchTweets(tso)

        # print rate limiting status
        #print "Current rate-limiting status: %i" % rs.getMetadata()['x-rate-limit-reset']

        # check if there are statuses returned and whether we still have work to do
        todo = not len(response['content']['statuses']) == 0

        # check all tweets according to their ID
        for tweet in response['content']['statuses']:
            tweet_id = tweet['id']
            print("Seen tweet with ID %i" % tweet_id)

            # current ID is lower than current next_max_id?
            if (tweet_id < next_max_id) or (next_max_id == 0):
                next_max_id = tweet_id