Step 4Python
You've got Python installed (w/ help from the link above) and now you need to get your packages in order.
Python - get the Python 2.7.2 Windows Installer from 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/
Refer to my How to install Python Packages on Windows 7 instructable if you need help installing these.
To run a python script, open it in IDLE and hit "Run > Run Module".
To learn about YOUR TWITTER KEY, goto the next step.
#######################################################################
#######################################################################
# twitterMentionMoodLight_python.py
# for use with twitterMentionMoodLight_arduino
# visit my instructables for more information
# http://www.instructables.com/member/pdxnat/
# http://python-twitter.googlecode.com/hg/doc/twitter.html
# http://dev.twitter.com/pages/rate_limiting_faq
print '<twitterMentionMoodLight>'
# import libraries
import twitter
import serial
import time
# connect to arduino via serial port
arduino = serial.Serial('COM4', 9600, timeout=1)
# establish OAuth id with twitter
api = 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 = "" # used in getMention()
# listen to arduino
def listenToArduino():
msg=arduino.readline()
if msg > '':
print 'arduino msg: '+msg.strip()
updateStatus(msg.strip())
# search for any mention of @yourUsername
def getMention():
status = api.GetReplies()
newID = str(status[0].id)
global oldID
if (newID != oldID):
oldID = newID
print status[0].text+", by @"+status[0].user.screen_name
arduino.write(1) # arduino gets 49
# post new message to twitter
def updateStatus(newMsg):
localtime = time.asctime(time.localtime(time.time()))
tweet = api.PostUpdate(newMsg+", "+localtime)
print "tweeted: "+tweet.text
while 1:
listenToArduino()
getMention()
time.sleep(15) # avoid twitter rate limit
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|











































