Come impostare “hourly” per la registrazione oraria con pywws

Introduzione

There are two quite different modes of operation with pywws. Traditionally pywws.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 pywws.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 pywws.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 pywws.Hourly more often than every 20 minutes.

Guida introduttiva

Prima di tutto, è necessario installare pywws e assicurarsi che si possono ottenere i dati dalla tua stazione meteo. Vedere Come iniziare con pywws per i dettagli.

Try running pywws.Hourly from the command line, with a high level of verbosity so you can see what’s happening. Use the pywws-hourly command to run pywws.Hourly:

pywws-hourly -vvv ~/weather/data

Entro cinque minuti (supponendo di aver impostato un intervallo di registrazione di 5 minuti) si dovrebbe vedere un messaggio “live_data new ptr”, seguita dal recupero di eventuali nuovi dati dalla stazione meteo ed elaborarli.

Cambiato nella versione 14.04.dev1194: the pywws-hourly command replaced scripts/pywws-hourly.py.

Percorsi dei file di configurazione

Aprire il file weather.ini con un editor di testo. Si dovrebbe avere una sezione di [paths] simile al seguente (dove xxx è il tuo nome utente):

[paths]
work = /tmp/weather
templates = /home/xxx/weather/templates/
graph_templates = /home/xxx/weather/graph_templates/
local_files = /home/xxx/weather/results/

Edit these to suit your installation and preferences. work is an existing temporary directory used to store intermediate files, templates is the directory where you keep your text template files, graph_templates is the directory where you keep your graph template files and local_files is a directory where template output that is not uploaded to your web site is put. Don’t use the pywws example directories for your templates, as they will get over-written when you upgrade 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. The pywws-version -v command should show you where the examples are on your computer.

Nuovo nella versione 14.04.dev1194: the pywws-version command.

Configurazione dell’esecuzione periodica

In weather.ini si dovrebbe avere le sezioni [logged], [hourly], [12 hourly] e [daily] simili ai seguenti:

[logged]
services = []
plot = []
text = []

[hourly]
...

These specify what pywws.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.

La voce services è un elenco di servizi meteo online per inviare i dati meteo. Le voci plot e text sono elenchi di file di modello grafico e file di testo per essere elaborati e, opzionalmente, caricati su un sito web. Aggiungere i nomi dei file di modello e servizi meteo alle voci appropriate, ad esempio:

[logged]
services = ['underground', 'metoffice']
plot = []
text = []

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

[12 hourly]
services = []
plot = []
text = []

[daily]
services = []
plot = ['28days.png.xml']
text = [('forecast.txt', 'T'), 'allmonths.txt']

Si noti l’uso del flag 'T' – questo dice a pywws si inviare il risultato a Twitter invece di caricarlo sul proprio sito ftp.

You can test that all these are working by removing the [last update] section from status.ini, then running pywws.Hourly again:

pywws-hourly -v ~/weather/data

Nuovo nella versione 14.05.dev1211: [cron name] sections. If you need more flexibility in when tasks are done you can use [cron name] sections. See weather.ini - configurazione del formato del file for more detail.

Cambiato nella versione 13.06_r1015: Aggiunto il flag 'T'. Precedentemente i modelli Twitter sono stati indicati separatamente in voci twitter in [hourly] e di altre sezioni. La sintassi precedente funziona ancora, ma è obsoleta.

Cambiato nella versione 13.05_r1009: the last update information was previously stored in weather.ini, with last update entries in several sections.

Eseguire con cron job

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 pywws.Hourly every hour, at zero minutes past the hour:

0 * * * *       pywws-hourly /home/xxx/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 pywws.Hourly and then emails you any output it produces. Here’s the script I use:

#!/bin/sh
#
# weather station logger calling script

export PATH=$PATH:/usr/local/bin

if [ ! -d ~/weather/data/ ]; then
  exit
  fi

log=/var/log/log-weather

pywws-hourly -v ~/weather/data >$log 2>&1

# mail the log file
/home/jim/scripts/email-log.sh $log "weather log"

Sarà necessario modificare questo file un bel pò per soddisfare i vostri percorsi di file e così via, ma dà un’idea di cosa fare.


Commenti o domande? Si prega di iscriversi per al mailing list pywws http://groups.google.com/group/pywws e facci sapere.