Twitter nämna Mood Light (4 / 7 steg)
Steg 4: Python
Har du Python installerade (med hjälp från länken ovan) och nu måste du få ditt paket i ordning.
Python - få Python 2.7.2 Windows Installer från http://www.python.org/download/
pySerial - http://pyserial.sourceforge.net/
simplejson - http://pypi.python.org/pypi/simplejson
httplib2 - http://code.google.com/p/httplib2/
python-oauth2 - https://github.com/simplegeo/python-oauth2
python-twitter - http://code.google.com/p/python-twitter/
Se min Hur installera Python-paket på Windows 7 instructable om du behöver hjälp med att installera dessa.
Att köra en python skript, öppna den i IDLE och tryck "Köra > Kör modul".
Vill veta om din TWITTER nyckel, gå till nästa steg.
#######################################################################
#######################################################################
# twitterMentionMoodLight_python.py
# för användning med twitterMentionMoodLight_arduino
# Besök min instructables mer information
#
# http://python-twitter.googlecode.com/hg/doc/twitter.html
# http://dev.twitter.com/pages/rate_limiting_faq
Print '< twitterMentionMoodLight >'
# import bibliotek
importera twitter
importera följetong
Importera tid
# ansluta till arduino via seriell port
Arduino = följetong. Serial ("COM4', 9600, timeout = 1)
# upprätta OAuth-id med twitter
API: t = twitter. API (consumer_key = 'YOUR_CONSUMER_KEY',
consumer_secret = 'YOUR_CONSUMER_SECRET',
access_token_key = 'YOUR_ACCESS_TOKEN_KEY',
access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET')
oldID = "" # används i getMention()
# lyssna på arduino
def listenToArduino():
MSG=Arduino.readline()
om msg > '':
skriva ut "arduino msg: ' +msg.strip()
updateStatus(msg.strip())
# Sök efter varje omnämnande av
def getMention():
status = api. GetReplies()
newID = str(status[0].id)
globala oldID
om (newID! = oldID):
oldID = newID
Skriv ut status [0] .text + ", av
Arduino.write(1) # arduino blir 49
# Skicka nytt meddelande på twitter
def updateStatus(newMsg):
localtime = time.asctime(time.localtime(time.time()))
Tweet = api. PostUpdate (newMsg + "," + localtime)
skriva ut "tweeted:" +tweet.text
medan 1:
listenToArduino()
getMention()
Time.Sleep(15) # undvika twitter hastighetsbegränsning