Skip to content

Instantly share code, notes, and snippets.

@mstyne
Created April 17, 2012 14:25
Show Gist options
  • Save mstyne/2406269 to your computer and use it in GitHub Desktop.
Save mstyne/2406269 to your computer and use it in GitHub Desktop.
Bogus aprs.fi api script
#!/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'
@mstyne
Copy link
Author

mstyne commented Apr 17, 2012

Bogus aprs.fi API call

Save the hatorade, IANAPD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment