forked from csfeeser/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNAPYA Lab 14 Solution
More file actions
67 lines (51 loc) · 1.7 KB
/
NAPYA Lab 14 Solution
File metadata and controls
67 lines (51 loc) · 1.7 KB
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
import turtle
import urllib.request
import json
import time
## Trace the ISS - earth-orbital space station
eoss = 'http://api.open-notify.org/iss-now.json'
## Call the webserv
trackiss = urllib.request.urlopen(eoss)
## put into file object
ztrack = trackiss.read()
## JSON to Python data structure conversion
result = json.loads(ztrack.decode('utf-8'))
## display our Pythonic data
print("\n\nConverted Python data")
print(result)
input('\nISS data retrieved & converted. Press the ENTER key to continue')
location = result['iss_position']
lat = location['latitude']
lon = location['longitude']
print('\nLatitude: ', lat)
print('Longitude: ', lon)
screen = turtle.Screen() # create a screen object
screen.setup(720, 360) # set the resolution
screen.setworldcoordinates(-180,-90,180,90)
screen.bgpic('iss_map.gif')
screen.register_shape('spriteiss.gif')
iss = turtle.Turtle()
iss.shape('spriteiss.gif')
iss.setheading(90)
lon = round(float(lon))
lat = round(float(lat))
iss.penup()
iss.goto(lon, lat)
## My location
yellowlat = 47.6
yellowlon = -122.3
mylocation = turtle.Turtle()
mylocation.penup()
mylocation.color('yellow')
mylocation.goto(yellowlon, yellowlat)
mylocation.dot(5)
mylocation.hideturtle()
passiss = 'http://api.open-notify.org/iss-pass.json'
passiss = passiss + '?lat=' + str(yellowlat) + '&lon=' + str(yellowlon)
response = urllib.request.urlopen(passiss)
result = json.loads(response.read().decode('utf-8'))
## print(result) ## uncomment to see the downloaded result
over = result['response'][1]['risetime']
style = ('Arial', 6, 'bold')
mylocation.write(time.ctime(over), font=style)
turtle.mainloop() # <-- this line should ALWAYS be at the bottom of your script. It prevents the graphic from closing!!!