如何让Twitter提到使用Python-Twitter做某事

时间:2014-09-10 23:57:07

标签: twitter arduino python-twitter

我正在使用Python-twitter Arduino打开Arduino板上的灯光,当有人在twitter中提到特定用户时。如果我使用我的用户名并使用此状态= api.GetUserTimeline('username'),我可以打开灯我想更喜欢当有人在twitter中的任何地方提到用户名时,此灯会亮起。任何想法我怎么能这样做?

以下是代码示例。

#status = api.GetUserTimeline('username') ##grab latest statuses

status = api.GetMentions(count=1) ##How get this to work properly?

checkIt = [s.text for s in status] ##put status in an array

drip = checkIt[0].split() ##split first tweet into words

## check for match and write to serial if match
if drip[0] == '#action_go':
    print 'Tweet Recieved, Turning the light on!'
    ser.write('1')
elif drip[0] == '#action_stop': ##break if done
    ser.write('0')
    print 'stopped, awaiting instructions.'
else:
    ser.write('0')
    print 'Awaiting Tweet'

1 个答案:

答案 0 :(得分:0)

您有两种选择。

首先,您可以查看您的提及 - https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline

调用该网址会向您显示最近提及的@username

如果您希望在提及后立即更换灯光,则需要使用Streaming API https://dev.twitter.com/streaming/reference/post/statuses/filter

@username设置过滤器,一旦被提及,您将立即收到提醒。