brunobord / Metar On Twitter
Pushing METAR data on Twitter
Clone this repository (size: 10.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/brunobord/metar-on-twitter/
| commit 7: | dd743ab79906 |
| parent 6: | 22d7e5edd871 |
| branch: | default |
| tags: | works-for-me |
drop the stdoutput of pyCurl
3 months ago
Changed (Δ116 bytes):
raw changeset »
metar_on_twitter.py (5 lines added, 0 lines removed)
Up to file-list metar_on_twitter.py:
| … | … | @@ -11,9 +11,11 @@ This (dumb) script is published under th |
11 |
11 |
See http://sam.zoy.org/wtfpl/ for more details on your rights. |
12 |
12 |
|
13 |
13 |
""" |
14 |
import sys |
|
14 |
15 |
import os |
15 |
16 |
from getpass import getpass |
16 |
17 |
import urllib2 |
18 |
from cStringIO import StringIO |
|
17 |
19 |
|
18 |
20 |
import simplejson |
19 |
21 |
import pycurl |
| … | … | @@ -24,6 +26,8 @@ DATA_DIR = os.path.join(ROOT, 'data') |
24 |
26 |
CONFIG = os.path.join(ROOT, 'config.py') |
25 |
27 |
METAR_URL = 'ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/%s.TXT' |
26 |
28 |
TWITTER_UPDATE = 'http://twitter.com/statuses/update.xml' |
29 |
DEV_NULL = StringIO() |
|
30 |
||
27 |
31 |
|
28 |
32 |
def create_config(): |
29 |
33 |
"Creates the configuration file out of nowhere" |
| … | … | @@ -78,6 +82,7 @@ def post_on_twitter(twitter_account, twi |
78 |
82 |
c.setopt(pycurl.USERPWD, "%s:%s" % (twitter_account, twitter_password)) |
79 |
83 |
c.setopt(pycurl.POST, 1) |
80 |
84 |
c.setopt(pycurl.POSTFIELDS, "status=%s" % metar_content) |
85 |
c.setopt(pycurl.WRITEFUNCTION, DEV_NULL.write) |
|
81 |
86 |
try: |
82 |
87 |
c.perform() |
83 |
88 |
c.close() |
