RxPy - 将实时Twitter流转换为Rx Observable?

时间:2016-11-09 01:40:42

标签: python reactive-programming tweepy reactivex rx-py

我跟着这个great tutorial使用tweepy来利用Python中的实时Twitter流。这将在提及RxJava,RxPy,RxScala或ReactiveX的实时时间打印推文。

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from rx import Observable, Observer

#Variables that contains the user credentials to access Twitter API
access_token = "CONFIDENTIAL"
access_token_secret = "CONFIDENTIAL"
consumer_key = "CONFIDENTIAL"
consumer_secret = "CONFIDENTIAL"


#This is a basic listener that just prints received tweets to stdout.
class TweetObserver(StreamListener):

    def on_data(self, data):
        print(data)
        return True

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



if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = TweetObserver()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    stream.filter(track=['rxjava','rxpy','reactivex','rxscala'])

这是通过ReactiveX变成RxPy Observable的完美候选人。但是我究竟如何将其转变为热源Observable?我似乎无法在任何地方找到有关如何执行Observable.create() ...

的文档

1 个答案:

答案 0 :(得分:0)

前段时间我想出来了。您必须定义一个操作传递的!=参数的函数。然后将其传递给mask = (df.c_id_x.eq(df.c_id_y)) print (df[mask]) p_id c_id_x c_id_y 1 4 45 63 2 37 21 36 4 4 15 67 5 34 21 30

Observer