Étape 3: Python
Vous avez un Python installé (avec l’aide du lien ci-dessus) et vous devez maintenant obtenir vos paquets dans l’ordre.
Python - obtenir Python 2.7.2 Windows Installer à partir d’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.
#######################################################################################
# simpleTweet_01_python.py
# visite mon instructables pour plus d’informations
#
imprimer « running... simpleTweet_01_python »
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')
# Ecoute pour arduino
def listenToArduino() :
MSG=Arduino.ReadLine()
Si msg > '' :
imprimer "arduino msg: ' +msg.strip()
compareMsg(msg.strip())
# éviter les messages en double
def compareMsg(newMsg) :
# comparer le premier mot de nouveaux et anciens
statut = api. GetUserTimeline('yourUsername')
prevMsg = [s.text s du statut]
pM = "" + prevMsg [0] + ""
pM = pM.split()
nM = newMsg.split()
imprimer "prevMsg:" + MP [0]
imprimer "newMsg:" + nM [0]
Si pM [0]! = nM [0] :
imprimer « bam »
postMsg(newMsg)
# message nouveau message sur twitter
def postMsg(newMsg) :
localtime = time.asctime(time.localtime(time.time()))
Tweet = api. PostUpdate (newMsg + "," + localtime)
imprimer "tweeté:" +tweet.text
tout en 1 :
listenToArduino()
#######################################################################################