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


Python Stream.filter方法代码示例

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


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

示例1: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def main():
	args = ArgParser.parse()
	#print 'credentials filename : ', args.credentials
	if args.credentials != None:

		print '********* Retreive credentials ****************'
		credentials = CredentialsReader.read(args.credentials)
		consumer_key = credentials['consumer_key']
		consumer_secret = credentials['consumer_secret']
		access_token = credentials['access_token']
		access_token_secret = credentials['access_token_secret']

		print '********* Twitter Authentication ***********'
		# Twitter authentification
		auth = OAuthHandler(consumer_key, consumer_secret)
		auth.set_access_token(access_token, access_token_secret)

		ol = OutputListener() # instance of OutputListener
		stream = Stream(auth=auth, listener=ol)

		# Start a stream
		print '************** Start a stream *****************'
		if args.kw_file != None and len(args.args_list) == 0:
			keywords = []
			with open (os.path.join(os.getcwd(), args.kw_file), 'r') as f:
				keywords = f.readlines()
			keywords = [x.strip('\n') for x in keywords]
			#print 'kewords from file: ', keywords
			stream.filter(track=keywords)
		elif args.kw_file is None and len(args.args_list) > 0:
			#print'args list:',  args.args_list
			stream.filter(track=args.args_list)
		else:
			print 'Impossible d\'utiliser les deux options en meme temps'
开发者ID:jkanc,项目名称:datamining,代码行数:36,代码来源:twitbot.py

示例2: __init__

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
    def __init__(self,slacker):

        # auth
        auth = OAuthHandler(settings.twitter_consumer_key, settings.twitter_consumer_secret)
        auth.set_access_token(settings.twitter_access_token, settings.twitter_access_token_secret)

        # out
        l = StdOutListener(slacker)

        # stream
        stream = Stream(auth, l)
        print("opening twitter stream")
        # if only a certain list
        if FILTER_LIST:
            api = API(auth)
            employees = api.list_members(LIST_USER,LIST)
            list = map(lambda val: str(val),employees.ids())
            #print(list)
            print("only List: "+LIST)
            stream.filter(follow=list)
        elif FILTER_KEYWORDS:
            print("only Keywords: "+str(KEYWORDS))
            stream.filter(track=KEYWORDS)
        else:
            print("your timeline")
            stream.userstream()
开发者ID:ixds,项目名称:twitterStreamToSlack,代码行数:28,代码来源:twitter.py

示例3: run

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
    def run(self):
        l = StdOutListener(self)
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)

        stream = Stream(auth, l)
        stream.filter(track=self.tags, languages=['en'])
开发者ID:jbulter,项目名称:Twitter_Stream,代码行数:9,代码来源:twitter_sink.py

示例4: TwitterStream

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def TwitterStream(kwords, lim, lang=['en'], loca=[-180, -90, 180, 90]):
    # print kwords, lang, lim, loca
    global limit
    if type(lim) != tuple:
        l = StdOutListener()
        limit = int(lim)
    else:
        day = int(lim[0])
        hour = int(lim[1])
        minute = int(lim[2])
        second = int(lim[3])
        l = StdOutListener_time()
        print time.time()
        limit = time.time() + 86400 * day + 3600 * \
            hour + 60 * minute + 1 * second
        print limit

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

    global results
    results = list()
    stream = Stream(auth, l)

    # print kwords, lang
    stream.filter(track=kwords, languages=['en'])
    # def filter(self, follow=None, track=None, async=False, locations=None,
    #            stall_warnings=False, languages=None, encoding='utf8'):
    return results
开发者ID:Slide-to-Display,项目名称:minionfo-web,代码行数:31,代码来源:TwitterStream.py

示例5: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def main():
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    backend = FileBackend("./test-db")
    stream = Stream(auth, l)
    stream.filter(track=['トレクル'])
开发者ID:gosu-clan,项目名称:twanki,代码行数:9,代码来源:twanki.py

示例6: startListen

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
    def startListen(self):
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
 
        stream = Stream(auth, self)
#     stream.filter(track=[positiveEmoticons])
        stream.filter(locations = [113.90625,-43.665217,157.148438,-13.35399])
开发者ID:s3341458,项目名称:python_twitter_analysis,代码行数:9,代码来源:Crawler.py

示例7: minetweets

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def minetweets():
    line = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, line)
    # stream.filter(track=['Watson', 'Cognitive', 'Machine Learning'])
    stream.filter(track=args, languages=["en"])
开发者ID:agrimrules,项目名称:SocialAnalytics,代码行数:9,代码来源:socialPy.py

示例8: setup_streams

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def setup_streams(auth):
    twitter_list = WBListener()
    #twitter_list2 = WBListener()
    global stream_obj

    stream_obj = Stream(auth, twitter_list)
    stream_obj.filter(track=['#trump'], async=True)
开发者ID:YoungMaker,项目名称:TwitterWhiteboard,代码行数:9,代码来源:twitter.py

示例9: run

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
    def run(self):
        global streamobj
        streamobj = Stream(self.auth, self.listener)

        #LOCATION OF USA = [-124.85, 24.39, -66.88, 49.38,] filter tweets from the USA, and are written in English
        streamobj.filter(locations = [-124.85, 24.39, -66.88, 49.38,], languages=['en'])
        return
开发者ID:tweetbot,项目名称:tweetbot,代码行数:9,代码来源:tweetbot.py

示例10: TweetFetcher

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
class TweetFetcher(StreamListener):
    def __init__(self, query, tweetstore, max_tweets=1000):
        super(TweetFetcher, self).__init__()
        self.tweet_store = tweetstore
        self._max_tweets = max_tweets
        self._query_terms = query.split()
        self._tweets = []
        self._count = 0
        self._alive = True
        auth = OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)

        self._stream = Stream(auth, self)
        self._stream.filter(track=self._query_terms, async=True)

    def on_data(self, data):
        if self._count < self._max_tweets and self._alive:
            tweet = json.loads(data)
            if tweet['lang'] == 'en':
                self.tweet_store.add_tweet(
                    {'guid': self._count, 'id': tweet['id'], 'text': tweet['text'], 'query': self._query_terms})

            self._count += 1
            return True
        else:
            print 'Reached tweet limit ... shutdown'
            return False

    def on_error(self, status):
        print 'Stream Error'
        print status
开发者ID:LukeDefeo,项目名称:TwitterSentiment,代码行数:33,代码来源:TweetFetcher.py

示例11: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def main():
#    dirname = os.path.dirname(inspect.getfile(inspect.currentframe()))
#    basename = os.path.basename(inspect.getfile(inspect.currentframe()))
    dirname = os.path.dirname(os.path.realpath(__file__))
    basename = os.path.basename(os.path.realpath(__file__))
    name_noextension = os.path.splitext(basename)[0]
    """Start log."""
    configinput = __import__("config" + name_noextension)
    outputDir = os.path.join(dirname, configinput.directory)
    if not os.path.exists(outputDir):
        os.makedirs(outputDir)
    logfilename = os.path.join(outputDir,basename) + ".log"
    logging.basicConfig(filename=logfilename,level=logging.DEBUG, format='%(asctime)s %(message)s')
    logging.info('Started')
    save_pid()


    """Execute the twitter api."""
    try:
        auth = OAuthHandler(configinput.consumer_key, configinput.consumer_secret)
        auth.set_access_token(configinput.access_token, configinput.access_secret)
        twitter_stream = Stream(auth, MyListener(os.path.join(dirname, configinput.directory), os.path.join(dirname, configinput.to_dir), basename))   # el segundo argumento es el nombre del archibvo json
        twitter_stream.filter(track=configinput.keyword_list_filter)
    except BaseException as e:
        logging.error('Failed to execute twitter api: ' + str(e))    
    
    logging.info('Finished')
开发者ID:amador2001,项目名称:ObservatorioHF,代码行数:29,代码来源:input.py

示例12: streamTweets

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def streamTweets(geobox, includeString, excludeString):
    '''Takes as inputs:
            geobox (latitudinal and longitudinal boundaries), a list of the form
            [W, S, E, N]
            includeString, terms to include, separated by line breaks
            excludeString, terms to include, separated by line breaks
    And then returns a stream of tweets, filtered by those inputs'''

    # gets term lists
    includeTerms = parseTerms(includeString)
    excludeTerms = parseTerms(excludeString)

    # USING TWITTER'S STREAMING API

    consumerKey = '****'
    consumerSecret = '****'

    # lets the app access twitter on behalf of my account
    accessToken = '****'
    accessSecret = '****'

    auth = OAuthHandler(consumerKey, consumerSecret)
    auth.set_access_token(accessToken, accessSecret)
     
    api = tweepy.API(auth)

    myListener = TwitterListener(includeTerms, excludeTerms)
    twitterStream = Stream(auth, myListener)
    twitterStream.filter(locations=geobox)

    return myListener.tweets
开发者ID:barborico,项目名称:TwitterMining,代码行数:33,代码来源:TwitterStreaming.py

示例13: start

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def start(args):

    if args["server"]:
        api.Run(nlp, userin, args["server"])
        if Config.TWITTER_CONSUMER_KEY != 'CONSUMER_KEY':
            auth = OAuthHandler(Config.TWITTER_CONSUMER_KEY, Config.TWITTER_CONSUMER_SECRET)
            auth.set_access_token(Config.TWITTER_ACCESS_KEY, Config.TWITTER_ACCESS_SECRET)
            userin.twitter_api = tweepy.API(auth)

            print("Listening Twitter mentions...")
            l = MentionListener(args)
            stream = Stream(auth, l)
            stream.filter(track=['DragonfireAI'], async=True)
    elif args["cli"]:
        while (True):
            com = raw_input("Enter your command: ")
            thread.start_new_thread(VirtualAssistant.command, (com, args))
            time.sleep(0.5)
    elif args["gspeech"]:
        from dragonfire.sr.gspeech import GspeechRecognizer
        recognizer = GspeechRecognizer()
        recognizer.recognize(args)
    else:
        from dragonfire.sr.deepspeech import DeepSpeechRecognizer
        recognizer = DeepSpeechRecognizer()
        recognizer.recognize(args)
开发者ID:igorstarki,项目名称:Dragonfire,代码行数:28,代码来源:__init__.py

示例14: storetwitterstream

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
    def storetwitterstream(self, destinationfile, query, lang=["fr"], starttime=time.time(), timelimit=60):

        class MyListener(StreamListener):
            def __init__(self, destinationfile, starttime, timelimit):
                self.outfile = self.TwitterApiUtil.db_location+destinationfile+".json"
                self.starttime=starttime
                self.timelimit=timelimit

            def on_data(self, data):
                while (time.time()-self.starttime)<self.timelimit:
                    try:
                        with open(self.outfile, 'a') as f:
                            f.write(data)
                            print(data)
                            return(True)
                    except BaseException as e:
                        print("Error on_data: %s" % str(e))
                        time.sleep(5)
                        pass
                    return(True)
                else: return(False)

            def on_error(self, status):
                print(status)
                return(True)

        twitter_stream = Stream(self.get_current_api().auth, MyListener(destinationfile,starttime,timelimit))
        twitter_stream.filter(track=query,languages=lang)
开发者ID:imachraoui,项目名称:DataViz_twitter,代码行数:30,代码来源:module_twitterscraping.py

示例15: streaming_tweets

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import filter [as 别名]
def streaming_tweets(keywords, language=["en"]):
    """
    @keywords   ==  search keywords, e.g. ["ImWithHer", "Trump"]
    @languages  ==  desired language, e.g.: ["en"]

    """

    filename = keywords[0].replace(" ", "").replace("#", "") + ".csv"
    print(filename)

    try:
        start_csv()
        while True:
            try:
                #Initialize Tweepy Streamer
                twitterStream = Stream(auth, TwitterListener())
                twitterStream.filter(track=keywords, languages=language)
            except Exception as error:
                print(error)
                print("[*] saving results to {}".format(filename))
                os.rename("streaming_results.csv", filename)

    except KeyboardInterrupt:
        print("[*] User KeyboardInterrupt: Tweepy Streamer Haulted")
        print("[*] saving results to {}".format(filename))
        os.rename("streaming_results.csv", filename)
开发者ID:jmausolf,项目名称:Twitter_Tweet_Counter,代码行数:28,代码来源:Streaming_Tweets.py


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