Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created February 12, 2016 16:32
Show Gist options
  • Save jpmens/0e29a74440317876e217 to your computer and use it in GitHub Desktop.
Save jpmens/0e29a74440317876e217 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import requests
import json
import paho.mqtt.publish as pahopub
hostname = 'localhost'
port = 1883
topic = 'owntracks/jpm/iss'
auth = { 'username' : 'xxx', 'password' : 'xxx' }
def iss_position():
data = None
try:
# http://open-notify.org/Open-Notify-API/ISS-Location-Now/
r = requests.get("http://api.open-notify.org/iss-now.json")
iss = json.loads(r.text)
data = {
'tid' : 'IS',
'lat' : iss['iss_position']['latitude'],
'lon' : iss['iss_position']['longitude'],
'tst' : iss['timestamp']
}
except Exception, e:
print str(e)
return data
if __name__ == '__main__':
iss = iss_position()
iss['_type'] = 'location'
payload = json.dumps(iss)
pahopub.single(topic, payload, hostname=hostname, port=port,
retain=True, auth=auth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment