How to configure pywws to post messages to Twitter¶
Create a Twitter account¶
You could post weather updates to your ‘normal’ Twitter account, but I think it’s better to have a separate account just for weather reports. This could be useful to someone who lives in your area, but doesn’t want to know what you had for breakfast.
Add location data (optional)¶
weather.ini file and add
longitude entries to the
[twitter] secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx latitude = 51.501 longitude = -0.142
Create a template¶
Twitter messages are generated using a template, just like creating files to upload to a website. Copy the example template ‘tweet.txt’ to your template directory, then test it:
python -m pywws.Template ~/weather/data ~/weather/templates/tweet.txt tweet.txt cat tweet.txt
~/weather/templates with your data and template directories.)
If you need to change the template (e.g. to change the units or language used) you can edit it now or later.
Post your first weather Tweet¶
Now everything is prepared for
ToTwitter to be run:
python -m pywws.ToTwitter ~/weather/data tweet.txt
If this works, your new Twitter account will have posted its first weather report. (You should delete the tweet.txt file now.)
Add Twitter updates to your hourly tasks¶
weather.ini file and edit the
[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.
You could change the
[12 hourly] or
[daily] sections instead, but I think
[hourly] is most appropriate for Twitter updates.
Changed in version 13.06_r1015: added the
Previously Twitter templates were listed separately in
[hourly] and other sections.
The older syntax still works, but is deprecated.
Include an image in your tweet¶
New in version 14.05.dev1216.
You can add up to four images to your tweets by specifying the image file locations in the tweet template.
Make the first line of the tweet
media path where
path is the absolute location of the file.
Repeat for any additional image files.
The “tweet_media.txt” example template shows how to do this.
The image could be from a web cam, or for a weather forecast it could be an icon representing the forecast.
To add a weather graph you need to make sure the graph is drawn before the tweet is sent.
I do this by using two
[cron xxx] sections in weather.ini:
[cron prehourly] format = 59 * * * * services =  plot = [('tweet.png.xml', 'L')] text =  [cron hourly] format = 0 * * * * services =  plot = ['7days.png.xml', '24hrs.png.xml', 'rose_12hrs.png.xml'] text = [('tweet_media.txt', 'T'), '24hrs.txt', '6hrs.txt', '7days.txt']
Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.