当前位置: 首页>>代码示例>>Python>>正文


Python TwitterSearch.search_tweets_iterable方法代码示例

本文整理汇总了Python中TwitterSearch.search_tweets_iterable方法的典型用法代码示例。如果您正苦于以下问题:Python TwitterSearch.search_tweets_iterable方法的具体用法?Python TwitterSearch.search_tweets_iterable怎么用?Python TwitterSearch.search_tweets_iterable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TwitterSearch的用法示例。


在下文中一共展示了TwitterSearch.search_tweets_iterable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_twitters

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def get_twitters():

	twitters = []
	tags = request.args.get('hashtags',False).replace('#','%23').replace('@','%40').replace(' ','').split(',')

	try:
		if len(tags)>=1:
			search_settings = TwitterSearchOrder() # create a TwitterSearchOrder object
			search_settings.set_include_entities(False) # and don't give us all those entity information
			search_settings.set_keywords( tags ) # let's define all words we would like to have a look for

			# it's about time to create a TwitterSearch object with our secret tokens
			search_on_twitter = TwitterSearch(
				consumer_key = APP_KEY,
				consumer_secret = APP_SECRET,
				access_token = OAUTH_TOKEN,
				access_token_secret = OAUTH_TOKEN_SECRET
			)
			# this is where the fun actually starsearch_on_twitter :)
			for twitter in search_on_twitter.search_tweets_iterable(search_settings):
				tw = { 'text' : twitter['text'], 'profile_image_url' : twitter['user']['profile_image_url'], 'name' : twitter['user']['name'], 'screen_name' : twitter['user']['screen_name'], 'location' : twitter['user']['location'] }
				if tw not in twitters:
					twitters.append( tw )
			# return json
			return json.dumps(twitters)
		else:
			return json.dumps([])
			
	except TwitterSearchException as e: # take care of all those ugly errors if there are some
		return json.dumps([])
开发者ID:silasvasconcelos,项目名称:tw-sort,代码行数:32,代码来源:application.py

示例2: __init__

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
    def __init__(self, consumer_key, consumer_secret, access_token, access_token_secret, keyword, since_id, tweet_count=15):
        self._results = []
        self._i = 0

        print("since_id: {0}".format(since_id))
        try:
            tso = TwitterSearchOrder()
            tso.set_keywords([keyword])
            tso.set_language('ja')
            tso.set_include_entities(False)
            tso.set_count(tweet_count)
            if since_id > 0:
                tso.set_since_id(long(since_id))

            ts = TwitterSearch(
                consumer_key = consumer_key,
                consumer_secret = consumer_secret,
                access_token = access_token,
                access_token_secret = access_token_secret
             )

            for tweet in ts.search_tweets_iterable(tso):
                self._results.append(
                    {
                        'screen_name': tweet['user']['screen_name'],
                        'user_name': tweet['user']['name'],
                        'profile_image_url': tweet['user']['profile_image_url'],
                        'text': tweet['text'],
                        'created_at': tweet['created_at'],
                        'id': tweet['id']
                    }
                )

        except TwitterSearchException as e:
            print(e)
开发者ID:koukomdev,项目名称:lambda_twitter_search,代码行数:37,代码来源:searchkeyword.py

示例3: __init__

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
class TweetSearch:
    def __init__(self):
        self.ts = TwitterSearch(
                consumer_key = 'uVp0jLzC043jvVxsoYtO7XnTy',
                consumer_secret = 'zHHqf6gaRGeLX9PS4YB4BMhcUo7p8dyI02cZLxVQOTnoHEG0gh', 
                access_token = '247768860-1BdrGZgXQibjaDSiZxGQ1MbjCxCEsM85gDFnRMjr',
                access_token_secret = 'ImetdaaKxq4uMvkQiMIxbGiR92ywqjYas52EZSXOyPu1t')
               # consumer_key = 'zTY2l3OYf9n50WgPG6KOCcr3J',
               # consumer_secret = 'sHqr1o1bCmW5xqPQE6wA7wCwsti00kT6hDnM6SlHNIr2kqStiJ', 
               # access_token = '597976696-zDOpw9mCLkJ05JKXemq9OAJ1qf6pjVg0G4zhtCrl',
               # access_token_secret = 'lmiwWH69u5MfDGWNhXaFlcyo4882uN2Fm7dYxcAPVPaAq')

    def search(self,keywords):
        print keywords
        tso = TwitterSearchOrder()
        tso.set_keywords(keywords)
        tso.set_language('en')
        tso.set_include_entities(False)
        tweets = None
        try:
            tweets = self.ts.search_tweets_iterable(tso)
            print tweets
        except TwitterSearchException as e: # catch all those ugly errors
            print(e)
        return tweets
开发者ID:Zishuo,项目名称:TwitterAnalyst,代码行数:27,代码来源:TweetsClaw.py

示例4: jobInteraction

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def jobInteraction(tag):

    tags = tag.split(",")
    tweets = []

    try:
        tso = TwitterSearchOrder()  # create a TwitterSearchOrder object
        tso.set_keywords(tags)  # let's define all words we would like to have a look for
        tso.set_language('es')  # we want to see German tweets only
        tso.set_include_entities(True)  # and don't give us all those entity information

        # it's about time to create a TwitterSearch object with our secret tokens
        ts = TwitterSearch(
            # consumer_key='QVhq5HVolTuzE79c16YDegtia',
            # consumer_secret='bfSPCAKXca52eaa2GF4a4mGceYVy4VkENwSuQtnr2c9e34TgWq',
            # access_token='1196870581-DfDo1GQQaukRZQBWn72ugdATSJqKPb4EaMsOFRK',
            # access_token_secret='tRV1lizrsCj8maKxOkzcDvp6vGJLBgDXH0ueEzmXSQTOi'
            consumer_key='gDEFFAToqZ1j5cE9SgJkeqvBY',
            consumer_secret='jqKGAra9Kd0n4jwsQXkhairyxx0uv9D4iMme6AeE2NLDX3fPfz',
            access_token='17160146-FxfSx4Bdq7SvuENSgHvi175f7uyjwoHCHVMUYiJQP',
            access_token_secret='SREyq0DxHOurUY5E0AbT3kPDwl5IFDcPFmnehZjbaH5ab'
        )

        # this is where the fun actually starts :)
        for tweet in ts.search_tweets_iterable(tso):
            # print('@%s tweeted: %s' % (tweet['user']['screen_name'], tweet['text']))
            tweets.append(tweet)

    except TwitterSearchException as e:  # take care of all those ugly errors if there are some
        print(e)

    print len(tweets)

    return json.dumps(tweets)
开发者ID:thebitisland,项目名称:business.init,代码行数:36,代码来源:api.py

示例5: search

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def search(query='cheeky nandos ledge banter', max=5):
    keywords = query.split()
    try:
        tso = TwitterSearchOrder()
        tso.set_keywords(keywords)
        # tso.set_language('en')
        # tso.set_include_entities(False)

        ts = TwitterSearch(
            consumer_key=app.config['TWITTER_CONSUMER_KEY'],
            consumer_secret=app.config['TWITTER_CONSUMER_SECRET'],
            access_token=app.config['TWITTER_ACCESS_TOKEN'],
            access_token_secret=app.config['TWITTER_TOKEN_SECRET']
        )
        results = []
        for tweet in ts.search_tweets_iterable(tso):
            results.append(tweet['id'])
            # print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )
            max -= 1
            if not max: break
        # print results
        return results

    except TwitterSearchException as e:  # take care of all those ugly errors if there are some
        print(e)
开发者ID:madeleine789,项目名称:sius-eventboard,代码行数:27,代码来源:tweets.py

示例6: search_results

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def search_results(words):

    #auth = OAuthHandler(keys.consumer_key, keys.consumer_secret)
    #auth.set_access_token(keys.access_token, keys.access_token_secret)

    try:

        tso = TwitterSearchOrder()
        tso.set_keywords(words)

        rilo_twitter = TwitterSearch(
            consumer_key = keys.consumer_key,
            consumer_secret = keys.consumer_secret,
            access_token = keys.access_token,
            access_token_secret = keys.access_token_secret
            )

        for tweet in rilo_twitter.search_tweets_iterable(tso):
            if  tweet['retweet_count'] > 150:
                #API.retweet(tweet['id'])
                print('@%s tweeted:  %s' % (tweet['user']['screen_name'], tweet['text']))
                print('\n\n\n')

    except TwitterSearchException as e:
        print (e)
开发者ID:belozi,项目名称:resume,代码行数:27,代码来源:twitter_app_01.py

示例7: mainLoop

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def mainLoop():
    try:
        tso = TwitterSearchOrder() # create a TwitterSearchOrder object
        tso.set_keywords([keyword1]) # let's define all words we would like to have a look for
        tso.set_language('en') # we want to see English tweets only
        tso.set_include_entities(False) # and don't give us all the entity information
    
        # create a TwitterSearch object with our secret tokens
        ts = TwitterSearch(
            consumer_key = consumerKey,
            consumer_secret = consumerSecret,
            access_token = accessToken,
            access_token_secret = accessSecret
         )
    # call API
        print "Checking for new tweets that match keywords: %s or %s" % (keyword1,keyword2)
        
        for tweet in ts.search_tweets_iterable(tso):
            
            # bind variables to information from tweets we're interested in
            username = (tweet['user']['screen_name']).encode('ascii', 'replace')
            tweetText = (tweet['text']).encode('ascii', 'replace')
            date = (tweet['created_at']).encode('ascii', 'replace')
            
            if isStringinCSV([username, tweetText, date]) == False: # check to see if individual tweet from TwitterSearch object is in our log
                print "New Tweet!"
                
                writeToCSV([username, tweetText, date]) # if so, write to log
        
        print "Check complete."
        
    except TwitterSearchException as e: # take care of all those ugly errors if there are any
        print(e)
开发者ID:Lbop,项目名称:JB,代码行数:35,代码来源:twitBackEnd_v01.py

示例8: getTweets

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def getTweets(username):
    tFeeds=[]
    try:
        #tuo = TwitterUserOrder(username) # create a TwitterUserOrder
        tso = TwitterSearchOrder() # create a TwitterSearchOrder object
        tso.set_keywords([username])
        tso.set_language('en')
        tso.set_count(50)
        tso.set_include_entities(False)
        tso.set_until(date.today()-timedelta(days=2))

        # it's about time to create TwitterSearch object
        ts = TwitterSearch(
            consumer_key = '%%%',
            consumer_secret = '^^^',
            access_token = '&&&',
            access_token_secret = '@@@'
        )

        # start asking Twitter
        counter=0
        for tweet in ts.search_tweets_iterable(tso):
            if (counter==300):
                break
            tweetx=str(tweet['text'].encode('ascii', 'ignore'))
            counter=counter+1
            tFeeds.append(tweetx)
            
    except TwitterSearchException as e: # catch all those ugly errors
        print(e)
        
    return tFeeds
开发者ID:yallapragada,项目名称:social_persona,代码行数:34,代码来源:persona.py

示例9: pull_tweet_responses

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def pull_tweet_responses(username, tweet_id):
    """
    Queries twitter for tweets mentioning user_id and afer tweet_id
    checks to see if found tweets are in response to tweet_id
    if response and not RT, saves relevant details to SQL database
    :param username:
    :param tweet_id:
    """
    try:
        tso = TwitterSearchOrder()
        tso.set_keywords(['@' + username])
        tso.set_language('en')
        tso.set_since_id(tweet_id)

        ts = TwitterSearch(
                consumer_key=api_key,
                consumer_secret=api_secret,
                access_token=access_token_key,
                access_token_secret=access_token_secret
        )
        for tweet in ts.search_tweets_iterable(tso):
            if tweet['in_reply_to_status_id'] == tweet_id and \
                            tweet['text'][:2] != 'RT':
                write_response_to_mysql(tweet)

    except TwitterSearchException as e:
        print('\nTweet id: ' + str(tweet_id))
        print(e)
开发者ID:asterix135,项目名称:CKME136,代码行数:30,代码来源:get_response_tweets.py

示例10: serve_twitter_news

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
 def serve_twitter_news(self):
     try:
         tso = TwitterSearchOrder()
         tso.set_keywords([topic])
         tso.set_language('en')
         tso.set_include_entities(False)
         
         ts = TwitterSearch(
             consumer_key = my_consumer_key,
             consumer_secret = my_consumer_secret,
             access_token = my_access_token,
             access_token_secret = my_access_token_secret
          )
          
         counter = 0
         batch_size = 5
         updates = []
         
         for tweet in ts.search_tweets_iterable(tso):
             update = '@%s: %s' % ( tweet['user']['screen_name'].encode('utf-8').strip(), tweet['text'].encode('utf-8').strip() )
             updates.append(update)
             logging.debug(update)
             counter += 1
             if counter >= batch_size:
                 self.send_JSON({ 'update' : updates })
                 break
     except TwitterSearchException as e:
         pass
开发者ID:mhausenblas,项目名称:ntil,代码行数:30,代码来源:ntil-server.py

示例11: retrieveTweets

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def retrieveTweets(keyword):
    try:
        tso = TwitterSearchOrder()
        tso.set_keywords([keyword])
        tso.set_language('en')
        tso.set_include_entities(False)
        ts = TwitterSearch(
            consumer_key = 'dxDoYB875ZUsvgPtp8EVDkyq6',
            consumer_secret = '6v4GiG1B3zKmJOsYPEtb0b39lv9da7iu7pIdAANyIoisoNrtZY',
            access_token = '2157789854-Fwr0uDJQ23twqSyxPEH0VnPwafQvpay8K2z7aFQ',
            access_token_secret = 'q9S6ECBpBv1RMBG8iNT8cYdoJvQAoIMZfMHAivs5Fh0PQ')

        htmlstring = ""
        print "lolpls"

        i = 0
        for tweet in ts.search_tweets_iterable(tso):
            htmlstring += "<div><strong><a href='http://twitter.com/%s'>@%s</a></strong> %s" % (tweet['user']['screen_name'], tweet['user']['screen_name'], tweet['text']) + '</div>'

            i += 1
            if i > 1:
                break

    except TwitterSearchException as e:
        print(e)

    return htmlstring
开发者ID:AndrewLikesFood,项目名称:InBrief,代码行数:29,代码来源:RetrieveTweets.py

示例12: search

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def search(text,limit):
	tweets_list = []
	try:
	    tso = TwitterSearchOrder() # create a TwitterSearchOrder object
	    tso.set_keywords(text) # let's define all words we would like to have a look for
	    tso.set_language('en') # we want to see English tweets only
	    tso.set_include_entities(False) # and don't give us all those entity information

	    # it's about time to create a TwitterSearch object with our secret tokens
	    ts = TwitterSearch(
		consumer_key = 	'tbHIo3PImh0pSIETLlO8wIKj4',
		consumer_secret = 'QmzJYSAp9rw6O7tDJATkm7Avq0OBRTfZbdNf3BjEmDmdDB1jT2',
		access_token = '1315897358-IkDrUD4Zdy6HP3FjF4UxdBqICEZOU91Lys95FGu',
		access_token_secret = 'nHROttog8743ZmeBWeldvh24EHwXtW4h1Z69o1GsgV2zE'
	     )

	     # this is where the fun actually starts :)
	    cnt=0
	    for tweet in ts.search_tweets_iterable(tso):
		cnt+=1
		if cnt>limit:
		    break
	        tweets_list.append(tweet['text'])
		#print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )
	    print cnt,'tweets'

	except TwitterSearchException as e: # take care of all those ugly errors if there are some
	    print(e)
	return tweets_list
开发者ID:SohiniMitra,项目名称:myapp,代码行数:31,代码来源:fetch.py

示例13: perform_search

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def perform_search(request):
    """Create a page that counts hashtags"""
    tag_to_search = ""
    if request.method == "POST":
        tag_to_search = request.POST["search"]
    keyword = '"#' + tag_to_search + '"'
    users = []
    postCount = 0
    hashCount = Counter()
    uniqueHashCount = Counter()

    # Now try and talk to twitter
    try:
        tso = TwitterSearchOrder()
        tso.set_keywords([keyword])  # This is the value we search for
        tso.set_include_entities(True)  # This is to include entity information, like Hashtags

        # This is the actual search. Secrets and key's have to be obtained from twitter, and aren't to be shared.
        ts = TwitterSearch(consumer_key="xxx", consumer_secret="yyy", access_token="qqq", access_token_secret="rrr")

        # This iterates through the found tweets
        for tweet in ts.search_tweets_iterable(tso):
            # count each tweet
            postCount += 1
            # Add the organize and record the tweets for later access
            add_tweet(tweet, users)
        # now count them
        count_hashtags(hashCount, uniqueHashCount, users)
        new_id = save_data(keyword.upper(), hashCount, uniqueHashCount, postCount, len(users))
    # catch errors
    except TwitterSearchException as e:  # take care of all those ugly errors if there are some
        return str(e)

    # return that string
    return search(request, new_id)
开发者ID:nehemiahnewell,项目名称:Hashtag_Analytics,代码行数:37,代码来源:views.py

示例14: crawl

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def crawl(filename, keywords, language):
    f = codecs.open(filename, "a", "utf-8")
    try:
        tso = TwitterSearchOrder()  # create a TwitterSearchOrder object
        tso.set_keywords(keywords)  # let's define all words we would like to have a look for
        tso.set_language(language)  # we want to see German tweets only
        tso.set_include_entities(False)  # and don't give us all those entity information

        # it's about time to create a TwitterSearch object with our secret tokens
        ts = TwitterSearch(
            consumer_key='MozbqzFag8UQMbuw9qkuyG7Fm',
            consumer_secret='c4m8EKOwQb90A3nLLySKSEkV7fVXe8taZq4IjgDrMVKihbNW4s',
            access_token='2684788650-VOzUZGhPItlgye6w5LhX5QMevWLK8WTALcxe8KM',
            access_token_secret='9IeW0F8XFnZ7FV5sCyZIahLEZBQTkzwO4L0q3vqRkl4je'
        )

        # this is where the fun actually starts :)
        for tweet in ts.search_tweets_iterable(tso):
            tweet_text = tweet['text'].replace("\n", " ")
            id1 = uuid.uuid4()
            id2 = uuid.uuid4()
            label = random_label()
            f.write('@%s\t%s\t%s\t%s\n' % (id1, id2, label, tweet_text))

    except TwitterSearchException as e:  # take care of all those ugly errors if there are some
        print(e)

    f.close()
开发者ID:dangchienhsgs,项目名称:twitter-sentiment-approach,代码行数:30,代码来源:crawl.py

示例15: twitterStreaming

# 需要导入模块: import TwitterSearch [as 别名]
# 或者: from TwitterSearch import search_tweets_iterable [as 别名]
def twitterStreaming():
    from time import sleep
    sleep(5)
    try:
        # it's about time to create a TwitterSearch object with our secret tokens
        tso = TwitterSearchOrder() # create a TwitterSearchOrder object
        tso.set_keywords(['Swissquote']) # let's define all words we would like to have a look for
        tso.set_language('en') # we want to see German tweets only
        tso.set_include_entities(False) # and don't give us all those entity information
        lastID = 569803155141206016
        tso.set_since_id(lastID)        
        ts = TwitterSearch(
            consumer_key = 'a',
            consumer_secret = 'a',
            access_token = 'a-a',
            access_token_secret = 'b'
        )
        for tweet in ts.search_tweets_iterable(tso):
            print( '[%s]@%s tweeted: %s' % ( tweet['created_at'], tweet['user']['screen_name'], tweet['text'] ) )
            if(lastID < tweet['id']):
                lastID = tweet['id']
            serveurStreaming.send(tweet['text'])
    except TwitterSearchException as e: # take care of all those ugly errors if there are some
        print(e)
    serveurStreaming.isConnectionAlive = False
开发者ID:sh19871122,项目名称:TM_2014-2015S2,代码行数:27,代码来源:twitterTestStreaming.py


注:本文中的TwitterSearch.search_tweets_iterable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。