-
Notifications
You must be signed in to change notification settings - Fork 0
/
iss.py
51 lines (37 loc) · 1 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
import requests
import json
import turtle
iss = turtle.Turtle()
def setup(window):
global iss
window.setup(1000, 500)
window.bgpic('earth.png')
window.setworldcoordinates(-180, -90, 180, 90)
turtle.register_shape("iss.gif")
iss.shape("iss.gif")
def move_iss(latitude, longitude):
global iss
iss.penup()
iss.goto(longitude, latitude)
iss.pendown()
def track_iss():
url = 'http://api.open-notify.org/iss-now.json'
response = requests.get(url)
if response.status_code == 200:
response_dict = json.loads(response.text)
position = response_dict['iss_position']
lat = float(position['latitude'])
long = float(position['longitude'])
move_iss(lat, long)
else:
print("error: ", response.status_code)
widget = turtle.getcanvas()
widget.after(5000, track_iss())
def main():
global iss
screen = turtle.Screen()
setup(screen)
track_iss()
if __name__ == "__main__":
main()
turtle.mainloop()