analitics

Pages

Monday, April 29, 2019

Python 3.7.3 : Get location of International Space Station.

Today I tested the urllib python module with python 3.7.3 and json python module.
The issue was to get the location of International Space Station - Open Notify.
The International Space Station is moving at close to 28,000 km/h so its location changes really fast! Where is it right now?
This is an open source project to provide a simple programming interface for some of NASA’s awesome data.
I do some of the work to take raw data and turn them into APIs related to space and spacecraft.
C:\Python373>python.exe
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD6
4)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> with urllib.request.urlopen('http://api.open-notify.org/iss-now.json') as f:
        print(f.read(300))
...
b'{"iss_position": {"longitude": "-86.9247", "latitude": "-38.3744"}, "message":
 "success", "timestamp": 1556575039}'
>>> with urllib.request.urlopen('http://api.open-notify.org/iss-now.json') as f:
...     source = f.read()
...     data = json.loads(source)
...
>>> print(data)
{'iss_position': {'longitude': '151.1941', 'latitude': '49.4702'}, 'message': 's
uccess', 'timestamp': 1556578621}
>>> print(data['iss_position']['longitude'])
151.1941
>>> print(data['iss_position']['latitude'])
49.4702
>>> print(data['message'])
success