-
Notifications
You must be signed in to change notification settings - Fork 2
/
iss.py
57 lines (49 loc) · 1.54 KB
/
iss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import turtle
import urllib.request
import time
import webbrowser
import geocoder
url = "http://api.open-notify.org/astros.json" # current astronauts on space station API
response = urllib.request.urlopen(url)
result = json.loads(response.read())
file = open("iss.txt", "w")
file.write("There are currently " +
str(result["number"]) + " astronauts on the ISS: \n\n")
people = result["people"]
for p in people:
file.write(p['name'] + " - on board" + "\n")
# print long and lat
g = geocoder.ip('me')
file.write("\nYour current lat / long is: " + str(g.latlng))
file.close()
webbrowser.open("iss.txt")
# world map gif in turtle
screen = turtle.Screen()
screen.setup(1280, 720)
screen.setworldcoordinates(-180, -90, 180, 90)
# load world map image
screen.bgpic("Map.gif")
screen.register_shape("ISS GIF2.gif")
iss = turtle.Turtle()
iss.shape("ISS GIF2.gif")
iss.setheading(45)
iss.penup()
while True:
# load the current status of the ISS in real-time
url = "http://api.open-notify.org/iss-now.json"
response = urllib.request.urlopen(url)
result = json.loads(response.read())
# Extract the ISS location
location = result["iss_position"]
lat = location['latitude']
lon = location['longitude']
# Ouput lon and lat to the terminal
lat = float(lat)
lon = float(lon)
print("\nLatitude: " + str(lat))
print("\nLongitude: " + str(lon))
# Update the ISS location on the map
iss.goto(lon, lat)
# Refresh each 5 seconds
time.sleep(5)