Created
February 12, 2016 16:32
-
-
Save jpmens/0e29a74440317876e217 to your computer and use it in GitHub Desktop.
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 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