0

完全是 Python 写作的菜鸟,所以请善待。我已经尝试了几个小时来解决这个问题,但我无法解决这个问题。我在 Python 中所做的唯一工作要简单得多,并且不涉及库。

我正在使用这个Python 代码在我的 Yún 上实现一个 Arduino 操作。它基于 Tweepy 库。我的主要目标是在 Arduino 中插入三个主题标签并根据发布的主题标签做 3 件不同的事情。因此,一切正常,每当发布任何主题标签时,我的 LED 都会闪烁。我现在想做的是在 Arduino 上运行的平分代码。

这是我的 streaming.py 代码的一部分:

search_string = '#jekotest'

class StdOutListener(StreamListener):

"""
A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""

def on_data(self, data):
    # I call an external script because the Arduino's Bridge library
    # confilcts with the tweepy library
    call(["/usr/bin/python", script_path + "/go.py"])
    return True

def on_error(self, status):
    # TODO: Put some error handling here
    return False

if __name__ == '__main__':
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    stream = Stream(auth, l)
    stream.filter(track=[search_string])

这是go.py:

import sys
sys.path.insert(0, '/usr/lib/python2.7/bridge/')

from bridgeclient import BridgeClient as bridgeclient

value = bridgeclient()
value.put('go','1')

我知道 stream.body 是一个包含 {'track': '#jekotest'} 的字典,所以:我怎么能做

if '#jekotest' in stream.body:
value.put('go', 1)
elif: 
'#anotherhashtag' in stream.body
value.put('go', 2)

等等?

太感谢了

4

1 回答 1

0

最后,我设法将两个文件放在一起并使其像这样工作:

hashtag = status.entities['hashtags']
    for value in hashtag:
        if translateHashtag1 in value['text']:
            goBridge.put('go', 1)
于 2016-05-31T15:57:53.363 回答