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


Python Stream.userstream方法代码示例

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


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

示例1: monitor

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
 def monitor(self, parent, connection):
     ntpclient = ntplib.NTPClient()
     silentChannelsFile = open("./modules/static/NOTWEETCHANNELS", 'r')
     accountsToMonitorFile = open("./modules/static/TWITTERACCOUNTS", 'r')
     self.silentChannels = silentChannelsFile.read().splitlines()
     self.accounts = accountsToMonitorFile.read().splitlines()
     silentChannelsFile.close()
     accountsToMonitorFile.close()
     cm = ChannelMessager()
     cm.setup(self.silentChannels, self.accounts, connection, parent)
     keyFile = open("modules/pubmsg/TwitterKeys", 'r')
     keyList = keyFile.read().splitlines()
     keyFile.close()
     for entry in keyList:
         if entry.startswith('#'):
             keyList.remove(entry)
     consumerKey = keyList[0]
     consumerSecret = keyList[1]
     accessKey = keyList[2]
     accessSecret = keyList[3]
     auth = OAuthHandler(consumerKey, consumerSecret)
     auth.set_access_token(accessKey, accessSecret)
     while True:
         stream = Stream(auth, cm, timeout=60)
         try:
             stream.userstream(_with='followings')
         except:
             print "Error, restarting stream"
开发者ID:TheCrittaC,项目名称:BigBen,代码行数:30,代码来源:monitortwitter.py

示例2: run

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
 def run(self,user,message):
     if utilities.getCommand() == "autotweet":
         streamListener = ReplyToTweet()
         streamListener.setAPI(self.twitterApi)
         streamListener.setUser(self.account_user_id)
         twitterStream = Stream(self.auth, streamListener)
         twitterStream.userstream(_with='user')
开发者ID:LeStarch,项目名称:AutoAck,代码行数:9,代码来源:Tweet.py

示例3: TwitterPlayer

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
class TwitterPlayer(player.Player):
    def __init__(self, model, code, access_token, access_token_secret, opponent):
        player.Player.__init__(self, model, code)
        self._opponent = opponent
        self._last_id = None

        self._auth = OAuthHandler(auth.consumer_key, auth.consumer_secret)
        self._auth.set_access_token(access_token, access_token_secret)
        self._api = API(self._auth)
        self._listener = TwitterListener(self, self._api)
        self._stream = Stream(self._auth, self._listener)

    @property
    def username(self):
        return self._auth.get_username()

    def allow(self):
        print 'This is the opponent\'s turn...'
        self._stream.userstream()

    def update(self, event):
        if event.player == self.code:
            return
        message = '@%s %s' % (self._opponent, self._model.events[-1][1])
        self.tweet(message)

    def tweet(self, message):
        if self._last_id is None:
            self._api.update_status(message)
        else:
            self._api.update_status(message, self._last_id)
开发者ID:benijake,项目名称:twishogi,代码行数:33,代码来源:player.py

示例4: __init__

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [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

示例5: StreamConsumerThreadClass

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
class StreamConsumerThreadClass(threading.Thread):
    def __init__(self, term="", oauthfile="", follow=False, user=False, track=False):
        threading.Thread.__init__(self)
        self.searchterm = term
        self.name = term
        self.consume = True
        self.follow = follow
        self.user = user
        self.track = track
        listener = MongoDBListener()

        try:
            oauth = json.loads(open(oauthfile, "r").read())

            if "consumer_key" in oauth:
                auth = OAuthHandler(oauth["consumer_key"], oauth["consumer_secret"])
                auth.set_access_token(oauth["access_token"], oauth["access_token_secret"])
                self.api = API(auth)

                if not self.api.verify_credentials():
                    raise Exception("Invalid credentials")

                self.stream = Stream(auth, listener, timeout=60)

        except:
            print "Error logging to Twitter"
            raise

    def stop_consume(self):
        self.stream.disconnect()

    def run(self):
        now = datetime.datetime.now()
        if self.user:
            print "Twitter Stream of the OAuth user: started at: %s" % (now)
        else:
            print "Twitter Stream with terms: %s started at: %s" % (self.getName(), now)

        connected = False
        while True:
            try:
                if not connected:
                    connected = True
                    if self.user:
                        self.stream.userstream(_with="followings")
                    elif self.follow:
                        user_ids = []
                        for user in self.api.lookup_users([], self.searchterm.split(","), False):
                            user_ids.append(user.id)
                        self.stream.filter(follow=[",".join("{0}".format(n) for n in user_ids)])
                    elif self.track:
                        self.stream.filter(track=[self.searchterm])

            except SSLError, sse:
                print sse
                connected = False
            except Exception, e:
                print "Stream error"
                raise e
开发者ID:openp2pdesign,项目名称:twitterstream-to-mongodb,代码行数:61,代码来源:twitterstreamtomongodb.py

示例6: handle

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
    def handle(self, *args, **options):
        l = StdOutListener()
        auth = tweepy.OAuthHandler('kFUnVwYAFmthrPg3P4MCDXRuf', 'LfY3zyzYEohCQLAH0f9ZuPE8Yok9ZXnyjAVvAJHNfYymgCwIsV')
        auth.set_access_token('2653803506-b9z9K01SaIChExXWlMnkwnpWAAzPPlsPzIEIE0k', 'PC6WIon73biuA87Wca2TuuincwFwzGyk78W4wWEFmIJNI')

        stream = Stream(auth, l)
        stream.userstream('HTR2014Live')
        return True
开发者ID:richardhomewood,项目名称:home-to-rome,代码行数:10,代码来源:stream.py

示例7: main

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


    streamListener = ReplyToTweet()
    twitterStream = Stream(auth, streamListener)
    # twitterStream.userstream(_with='user')
    print "Ready to listen."
    twitterStream.userstream(replies=all)
开发者ID:eyspahn,项目名称:OnlineHateSpeech,代码行数:10,代码来源:twitterbot_hatespeech.py

示例8: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def main():
    (options, args) = get_parser()
    auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    api = API(auth_handler=auth)
    stream = Stream(auth, CustomStreamListener(api, options))
    stream.timeout = None
    stream.userstream()
开发者ID:aomoriringo,项目名称:number_bot,代码行数:10,代码来源:number_bot.py

示例9: streamTwitter

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
 def streamTwitter(self):
     Log.record('\tWill Read From Config')
     self.readFromConfig()
     Log.record('\tWill Log into Twitter')
     api = self.loginToTwitter()
     Log.record('\tWill Stream Tweets from Twitter')
     stream = Stream(self.api.auth, StdOutListener())
     stream.userstream('survey11909')
开发者ID:ShyamThiagarajan,项目名称:TwitterApp,代码行数:10,代码来源:Stream_Timeline_Tweets.py

示例10: main_loop

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def main_loop():
  global can_send_after
  while 1:
    message = ircsock.recv(2048) # Receive data from the server.
    message = message.strip('\n\r') # Remove any unnecessary linebreaks.

    print message

    if "PING :" in message: pong(message)

    # Only respond to chat from the current chatroom (not private or administrative log in messages).
    if splitter not in message: continue

    # Get the content of the message.
    user = message.split("!")[0][1:]
    message = message.split(splitter)[1]

    # Convert to lowercase and split the message based on whitespace.
    split = message.lower().split()

    if split[0] == args.nick.lower() + ":":   # Command addressed to the bot (e.g. learn or forget).
      if split[1] == "learn" and len(split) > 2:
        learn(split[2], message.split()[3:], user)
      elif split[1] == "forget" and len(split) == 3:
        forget(split[2])
      elif split[1] == "help":
        send_help()
      elif split[1] == "quiet" and len(split) == 2:
        can_send_after = datetime.now() + timedelta(seconds=args.quiet)
        send("Whatever you say.", user, True)
      elif split[1] == "quiet" and len(split) == 3 and is_positive_number(split[2]):
        can_send_after = datetime.now() + timedelta(seconds=int(split[2]))
        send("Whatever you say.", user, True)
      elif split[1] == "speak" and len(split) == 2:
        can_send_after = datetime.now()
      elif split[1] == "list" and len(split) == 2:
        send("Builtin commands: [" + ", ".join(default_commands) + "]")
        send("User commands: [" + ", ".join(user_commands) + "]")
      elif split[1] == "blame" and len(split) == 3:
        if split[2] in default_commands:
          send(split[2] + " is a default command.", user)
        elif split[2] in user_commands:
          send(split[2] + " was created by " + user_commands[split[2]][1], user)
        else:
          send("That's not a valid keyword!", user)
      elif split[1] == "autotweet" and len(split) > 2:
        streamListener = ReplyToTweet()
        twitterStream = Stream(auth, streamListener)
        twitterStream.userstream(_with='user')
        send("AutoTweeting...", user, True)
      elif split[1] == "autofbook" and len(split) > 2:
        PostToWall()
        send("AutoFbooking...", user, True)
      else:
        send("How may I help you?", user)
    else:   # Only handle messages that aren't sent directly to the bot.
      handle(message.lower(), default_commands)
      handle(message.lower(), user_commands)
开发者ID:tpalsulich,项目名称:AutoAck,代码行数:60,代码来源:autoack.py

示例11: listen

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def listen():
    start_twitter()
    try:
        app_exfiltrate.log_message('info', "[twitter] Listening for DMs...")
        stream = Stream(auth, StdOutListener())
        stream.userstream()
    except Exception, e:
        app_exfiltrate.log_message(
            'warning', "[twitter] Couldn't listen for Twitter DMs".format(e))
开发者ID:Exploit-install,项目名称:DET,代码行数:11,代码来源:twitter.py

示例12: run

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
	def run(self):
		log_info(str(timestamp()) + ": Starting "+ self.name)
		keyfile = open('twitter_keys.txt', 'r')
		cfg = json.loads(keyfile.read()) #todo: load from config file
		api = get_api(cfg)
		auth = OAuthHandler(cfg['consumer_key'], cfg['consumer_secret'])
		auth.set_access_token(cfg['access_token'], cfg['access_token_secret'])
		streamListener = ProcessTweet()
		twitterStream = Stream(auth, streamListener)
		twitterStream.userstream()
开发者ID:macarr,项目名称:shibebot,代码行数:12,代码来源:shibebotthreaded.py

示例13: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def main():
    try:
        stream = Stream(auth, CustomStreamListener())
        stream.timeout = None

        #userstreamの開始
        print("start")
        stream.userstream()
    except KeyboardInterrupt :
        print("\nexit: KeyboardInterrupt")
        return
开发者ID:sga0221,项目名称:sga_bot_tes,代码行数:13,代码来源:twi_fav.py

示例14: main

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def main():
   	try:
		auth = OAuthHandler(consumer_key, consumer_secret)
		auth.secure = True
		auth.set_access_token(access_token, access_token_secret)
		api = API(auth)
		print(api.me().name)
		stream = Stream(auth, StdOutListener())
		stream.userstream()

    	except BaseException as e:
        	print("Error in main()", e)
开发者ID:zweed4u,项目名称:freeGuacAndChips,代码行数:14,代码来源:chipotleDM.py

示例15: openStream

# 需要导入模块: from tweepy import Stream [as 别名]
# 或者: from tweepy.Stream import userstream [as 别名]
def openStream():
    listener = TweetListener()
    stream = Stream(auth, listener, timeout=60)  
    connected = False
    while True:
        try: 
            if not connected:
                connected = True
                stream.userstream()
        except SSLError, e:
            print e
            connected = False
开发者ID:JohnCoogan,项目名称:group-chat,代码行数:14,代码来源:groupchat.py


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