There are two quite different modes of operation with pywws. Traditionally Hourly would be run at regular intervals (usually an hour) from cron. This is suitable for fairly static websites, but more frequent updates can be useful for sites such as Weather Underground (http://www.wunderground.com/). The newer LiveLog program runs continuously and can upload data every 48 seconds.
Note that although this document (and the program name) refers to ‘hourly’ logging, you can run Hourly as often or as infrequently as you like, but don’t try to run it more often than double your logging interval. For example, if your logging interval is 10 minutes, don’t run Hourly more often than every 20 minutes.
Avant tout, vous devez installer pywws et vous assurer qu’il reçoit bien les informations de votre station météo. Voir Comment démarrer avec pywws pour plus de détails.
Try running Hourly from the command line, with a high level of verbosity so you can see what’s happening:
python -m pywws.Hourly -vvv ~/weather/data
En moins de cinq minutes (assumant que votre intervalle de relevé soit de 5 minutes) vous devriez voir le message ‘live_data new ptr’, suivi par la recherche et le traitement de nouvelles données de la station météorologique.
Ouvrez votre fichier weather.ini avec un éditeur de texte. Vous devriez avoir une section [paths] similaire à ce qui suit (où xxx est votre nom d’usager):
[paths]
work = /tmp/weather
templates = /home/xxx/weather/templates/
graph_templates = /home/xxx/weather/graph_templates/
Éditez pour correspondre à votre installation et à vos préférences. work est un dossier temporaire utilisé pour emmagasiner les fichiers intermédiaires, templates est le dossier où vous gardez vos fichiers de gabarit texte et graph_templates est le dossier où vous gardez vos fichiers de gabarit graphes. Ne pas utiliser les dossiers exemple de pywws pour celà, puisqu’ils seront écrasés lors de mise à jour de pywws.
Copy your text and graph templates to the appropriate directories. You may find some of the examples provided with pywws useful to get started. If you installed pywws with pip the examples should be in /usr/share/pywws or /usr/local/share/pywws or similar.
Dans weather.ini vous devriez avoir les sections [logged], [hourly], [12 hourly] et [daily] similaires à celle-ci:
[logged]
services = []
twitter = []
plot = []
text = []
[hourly]
...
These specify what Hourly should do when it is run. Tasks in the [logged] section are done every time there is new logged data, tasks in the [hourly] section are done every hour, tasks in the [12 hourly] section are done twice daily and tasks in the [daily] section are done once per day.
Les entrées dans services sont une liste de services météo en ligne sur lesquels envoyer vos données météo. Les entrées plot et text sont des listes de fichiers gabarits graphes et textes à téléverser sur votre site web, et l’entrée twitter est une liste de gabarits pour les messages à poster sur Twitter. Ajoutez le nom de vos fichiers de gabarit et de services météo à l’entrée correspondante, par exemple:
[logged]
services = ['underground', 'metoffice']
twitter = []
plot = []
text = []
[hourly]
services = []
twitter = ['tweet.txt']
plot = ['7days.png.xml', '24hrs.png.xml', 'rose_24hrs.png.xml']
text = ['24hrs.txt', '6hrs.txt', '7days.txt']
[12 hourly]
services = []
twitter = []
plot = []
text = []
[daily]
services = []
twitter = ['forecast.txt']
plot = ['28days.png.xml']
text = ['allmonths.txt']
You can test that all these are working by removing all last update lines from weather.ini then run Hourly again:
python -m pywws.Hourly -v ~/weather/data
The pywws installation includes a short script pywws-hourly.py that gets installed in /usr/bin or /usr/local/bin or similar. You should be able to use this script to run Hourly:
pywws-hourly.py -v ~/weather/data
Most UNIX/Linux systems have a ‘cron’ daemon that can run programs at certain times, even if you are not logged in to the computer. You edit a ‘crontab’ file to specify what to run and when to run it. For example, to run Hourly every hour, at zero minutes past the hour:
0 * * * * pywws-hourly.py /home/jim/weather/data
This might work, but if it didn’t you probably won’t get any error messages to tell you what went wrong. It’s much better to run a script that runs Hourly and then emails you any output it produces. Here’s the script I use:
#!/bin/sh
#
# weather station logger calling script
if [ ! -d /data/weather/ ]; then
exit
fi
log=/var/log/log-weather
pywws-hourly.py -v /data/weather >$log 2>&1
# mail the log file
/home/jim/scripts/email-log.sh $log "weather log"
Vous devrez éditer beaucoup pour adapter à vos emplacements de dossier et ainsi de suite, mais il donne une certaine idée de ce qui peut être fait.
Commentaires ou questions? SVP, souscrivez à la liste d’envoi de pywws http://groups.google.com/group/pywws et laissez-le nous savoir.