-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
66 lines (52 loc) · 1.55 KB
/
app.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
from flask import Flask,redirect, url_for ,render_template,request
import os
import json
import turtle
import urllib.request
import time
import webbrowser
import geocoder
app = Flask(__name__)
picFolder = os.path.join('static','pics')
app.config['UPLOAD_FOLDER'] = picFolder
def iss():
# Setup the world map in turtle module
screen = turtle.Screen()
screen.setup(1200, 700)
screen.setworldcoordinates(-180, -90, 180, 90)
# load the world map image
screen.bgpic("mapg.gif")
screen.register_shape("issg.gif")
iss = turtle.Turtle()
iss.shape("issg.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)
@app.route('/')
def home():
map = os.path.join(app.config['UPLOAD_FOLDER'],'worldmap.jpg')
return render_template('index.html', map_pic = map)
# return iss()
@app.route('/send', methods=['GET','POST'])
def send():
if request.method =='POST':
return iss()
if __name__ == '__main__':
app.run(debug=True)