Étape 4: Python
Vous avez un Python installé (avec l’aide du lien ci-dessus) et vous devez maintenant obtenir vos paquets dans l’ordre.
Python - Téléchargez Windows Installer Python 2.7.2 de 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 référer à ma façon d’installer les paquets Python sur Windows 7 instructable si vous avez besoin d’aide pour installer ces.
Pour exécuter un python script, ouvrez-le en IDLE et appuyez sur « Run > Run Module ».
Se renseigner sur votre clé de TWITTER, goto, l’étape suivante.
#######################################################################
#######################################################################
# twitterMentionMoodLight_python.py
# pour une utilisation avec twitterMentionMoodLight_arduino
# visite mon instructables pour plus d’informations
#
# http://python-twitter.googlecode.com/hg/doc/twitter.html
# http://dev.twitter.com/pages/rate_limiting_faq
Print « < twitterMentionMoodLight > »
bibliothèques d’importation #
importation de twitter
importation de série
moment de l’importation
# se connecter à arduino via un port série
Arduino = serial. Série (« COM4 », 9600, timeout = 1)
# créer id OAuth avec 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 = "" # utilisé dans getMention()
# Ecoute pour arduino
def listenToArduino() :
MSG=Arduino.ReadLine()
Si msg > '' :
imprimer "arduino msg: ' +msg.strip()
updateStatus(msg.strip())
# Recherchez n’importe quelle mention de
def getMention() :
statut = api. GetReplies()
newID = str(status[0].id)
oldID global
Si (newID! = oldID) :
oldID = newID
imprimer le statut [0] .text + ", par
Arduino.Write(1) # arduino obtient 49
# message nouveau message sur twitter
def updateStatus(newMsg) :
localtime = time.asctime(time.localtime(time.time()))
Tweet = api. PostUpdate (newMsg + "," + localtime)
imprimer "tweeté:" +tweet.text
tout en 1 :
listenToArduino()
getMention()
Time.Sleep(15) # éviter les pulsations twitter