Created
April 17, 2012 14:25
-
-
Save mstyne/2406269 to your computer and use it in GitHub Desktop.
Bogus aprs.fi api script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import httplib | |
import json | |
# import socket | |
import sys | |
import time | |
apikey = 'XXX' | |
apiurl = 'api.aprs.fi' | |
ssid = 'K2MTS-1' | |
conn = httplib.HTTPConnection(apiurl) | |
try: | |
conn.request('GET', '/api/get?name=' + ssid + '&what=wx&apikey=' + apikey + '&format=json') | |
# except socket.gaierror: | |
except: | |
print "Couldn't query aprs.fi! Sorry!\n" | |
sys.exit() | |
try: | |
response = conn.getresponse() | |
except: | |
print "Couldn't get a response from aprs.fi! Sorry!\n" | |
sys.exit() | |
result = response.read() | |
try: | |
jresult = json.loads(result) | |
except: | |
print "Couldn't parse JSON from aprs.fi! Sorry!\n" | |
sys.exit() | |
# print type(jresult) | |
entries = jresult['entries'][0] | |
temp = entries['temp'] | |
ts = entries['time'] | |
wind = entries['wind_gust'] | |
print 'K2MTS-1 ' + time.ctime(float(ts)) + ' Observation' | |
print 'Temperature: ' + temp + 'C' | |
print 'Wind Gust: ' + wind + 'm/s' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bogus aprs.fi API call
Save the hatorade, IANAPD