-
Notifications
You must be signed in to change notification settings - Fork 1
/
tracker.py
85 lines (64 loc) · 1.87 KB
/
tracker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import json
import turtle
import urllib.request
import time
# Initalize the turtle screen
screen = turtle.Screen()
screen.setup(1280,720)
screen.setworldcoordinates(-180,-90,180,90)
# Load in the map and the ISS
screen.bgpic("map.gif")
screen.register_shape("iss.gif")
# Long text
longt = turtle.Turtle()
longt.penup()
longt.hideturtle()
# Lat text
latit = turtle.Turtle()
latit.penup()
latit.hideturtle()
# Line draw
line = turtle.Turtle()
line.penup()
line.hideturtle()
# ISS Shape
iss = turtle.Turtle()
iss.shape("iss.gif")
iss.setheading(45)
iss.penup()
#Velocity Text
velocityText = turtle.Turtle()
velocityText.penup()
velocityText.hideturtle()
font= ("Arial", 15, "normal")
# Update the location on the screen
while True:
try:
# ISS Long + Lat API
url = "http://api.open-notify.org/iss-now.json"
response = urllib.request.urlopen(url)
result = json.loads(response.read())
# Orbital Velocity API
url2 = "https://api.wheretheiss.at/v1/satellites/25544"
response2= urllib.request.urlopen(url2)
result2 = json.loads(response2.read())
except:
print("API fetching failed.")
# Load in values from the API
latitude = float(result["iss_position"]["latitude"])
longitude = float(result["iss_position"]["longitude"])
velocity = float(result2["velocity"])
longt.goto(0,-80)
latit.goto(0,-75)
velocityText.goto(0,-85)
iss.goto(longitude,latitude) #update shape position with the new long,
line.goto(longitude,latitude)
line.pencolor("red")
line.pendown()
longt.clear()
longt.write("Longitude: "+str(longitude),font, align="left")
latit.clear()
latit.write("Latitude: " + str(latitude),font, align="left")
velocityText.clear()
velocityText.write("Velocity: "+ str(velocity) + " km/h",font, align="left")
time.sleep(5) # Update every 5s =