Come configurare pywws per pubblicare messaggi su Twitter¶
Installare le dipendenze¶
Postare su Twitter richiede alcuni software aggiuntivi. Vedere Dipendenze - Postare su Twitter.
Creare un account su Twitter¶
Si potrebbero postare aggiornamenti meteo all’account “normale” di Twitter, ma penso che sia meglio avere un conto separato solo per i bollettini meteo. Questo potrebbe essere utile a qualcuno che vive nella tua zona, ma non vuole sapere quello che avevi per la prima colazione.
Autorizzare pywws per inviare al tuo account di Twitter¶
Se si esegue pywws su un dispositivo di bassa potenza come un router, potrebbe essere più facile per eseguire questo passaggio di autorizzazione su un altro computer, sempre che ci sia `` python-oauth2 `` installato. Utilizzare una directory “data” vuota – il file weather.ini
verrà creato i cui contenuti possono essere copiati nel file weather.ini
reale utilizzando qualsiasi editor di testo.
Assicurarsi che non vi siano altri software pywws in esecuzione, quindi su esegui TwitterAuth
:
python -m pywws.TwitterAuth ~/weather/data
(Replace ~/weather/data
with your data directory.)
In questo modo, si apre una finestra del browser web (o un URL da copiare nel il browser web) dove è possibile accedere al proprio account Twitter e autorizzare pywws. Il browser visualizzerà 7 cifre che è necessario copiare nel programma TwitterAuth
. Se ha successo, il file weather.ini
avrà una sezione [twitter]
con le voci secret
and key
. (Non rivelare a nessun altro.)
Aggiungere i dati di localizzazione (opzionale)¶
Modificare il file weather.ini
e aggiungere voci latitude
e longitude
nella sezione [twitter]
. Ad esempio:
[twitter]
secret = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
latitude = 51.501
longitude = -0.142
Creare un modello¶
I messaggi Twitter vengono generati utilizzando un modello, proprio come la creazione di file da caricare su un sito Web. Copia il modello di esempio “tweet.txt” directory dei modelli testo, poi testalo:
python -m pywws.Template ~/weather/data ~/weather/templates/tweet.txt tweet.txt
cat tweet.txt
(Replace ~/weather/data
and ~/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.
Pubblicare il tuo primo Meteo Tweet¶
Ora tutto è pronto per ToTwitter
essere eseguito:
python -m pywws.ToTwitter ~/weather/data tweet.txt
Se questo funziona, il vostro nuovo account Twitter, ha pubblicato il suo primo Meteo report. (È necessario eliminare il file tweet.txt).
Aggiungere aggiornamenti Twitter alla tua attività oraria¶
Modificare il file weather.ini
e modificare la sezione [hourly]
. Ad esempio:
[hourly]
services = []
plot = ['7days.png.xml', '24hrs.png.xml', 'rose_12hrs.png.xml']
text = [('tweet.txt', 'T'), '24hrs.txt', '6hrs.txt', '7days.txt']
Si noti l’uso del flag 'T'
– questo dice a pywws si inviare il risultato a tweet invece di caricarlo sul il sito ftp.
Invece si potrebbe cambiare le sezioni [logged]
, [12 hourly]
o [daily]
, ma credo che ogni [hourly]
è più appropriato per gli aggiornamenti di Twitter.
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.
Include an image in your tweet¶
Nuovo nella versione 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']
Commenti o domande? Si prega di iscriversi per al mailing list pywws http://groups.google.com/group/pywws e facci sapere.