Comment configurer pywws pour poster des messages sur Twitter

Install dependencies

Note: simplejson est inclu dans Python 2.6+

Create a Twitter account

Vous pouvez poster des mise à jour météo sur votre compte Twitter ‘normal’, mais je crois qu’il est préférable d’avoir un compte distinct réservé à vos relevés météo. Ce qui pourrait être fort utile à une personne vivant dans votre voisinage, mais ne souhaitant pas savoir ce que vous avez pris au petit déjeuner.

Authorise pywws to post to your Twitter account

Make sure no other pywws software is running, then run TwitterAuth:

python -m pywws.TwitterAuth /data/weather

(Remplacez /data/weather par votre répertoire de données.)

This will open a web browser window (or give you a URL to copy to your web browser) where you can log in to your Twitter account and authorise pywws to post. Your web browser will then show a 7 digit number which you need to copy to the TwitterAuth program. If successful, your weather.ini file will now have a [twitter] section with secret and key entries. (Don’t disclose these to anyone else.)

Add location data (optional)

Edit your weather.ini file and add latitude and longitude entries to the [twitter] section. For example:

[twitter]
secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
latitude = 51.501
longitude = -0.142

Create a template

Les messages pour Twitter sont générés en utilisant un gabarit, tout comme sont créés les fichiers à téléverser sur votre site web. Copiez le gabarit exemple ‘tweet.txt’ dans votre dossier de gabarit, puis testez-le:

python -m pywws.Template /data/weather ~/weather/templates/tweet.txt tweet.txt
cat tweet.txt

(Remplacez /data/weather et ~/weather/templates par vos répertoires de données et de gabarits.) Si vous avez besoin de modifier le gabarit (ex. pour changer les unités de mesure ou la langue utilisée) vous pouvez l’éditer maintenant ou ultérieurement.

Post your first weather Tweet

Now everything is prepared for ToTwitter to be run:

python -m pywws.ToTwitter /data/weather tweet.txt

Si celà fonctionne, Votre nouveau compte Twitter aura posté son premier relevé météo. (Vous devriez supprimer le fichier tweet.txt maintenant.)

Add Twitter updates to your hourly tasks

Edit your weather.ini file and edit the [hourly] section. For example:

[hourly]
services = []
plot = ['7days.png.xml', '24hrs.png.xml', 'rose_12hrs.png.xml']
text = [('tweet.txt', 'T'), '24hrs.txt', '6hrs.txt', '7days.txt']

Note the use of the 'T' flag – this tells pywws to tweet the template result instead of uploading it to your ftp site.

Vous pourriez tout aussi bien choisir de plutôt modifier les sections [logged], [12 hourly] ou [daily], mais je crois que [hourly] est le plus approprié pour les envois sur Twitter.

Commentaires ou questions? SVP, souscrivez à la liste d’envoi de pywws http://groups.google.com/group/pywws et laissez-le nous savoir.