-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPOD_viewer.py
47 lines (40 loc) · 1.52 KB
/
APOD_viewer.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
from flask import Flask, render_template, request
import requests
import datetime
def getData():
API_KEY = "CtpP4rkxqLb297YpfL9T9m1X6UPNgqzpA6BiaW2y"
url = f"https://api.nasa.gov/planetary/apod?api_key={API_KEY}"
today = datetime.datetime.now().date()
data = {"filter_type": "single",
"start_date": today,
"end_date": today,
"n_images": 1,
"today": today}
if request.method == "POST":
match request.form["filter_type"]:
case "single":
url += f"&start_date={request.form['start_date']}"
url += f"&end_date={request.form['start_date']}"
case "range":
url += f"&start_date={request.form['start_date']}"
url += f"&end_date={request.form['end_date']}"
case "random":
url += f"&count={request.form['n_images']}"
data["filter_type"] = request.form["filter_type"]
data["start_date"] = request.form["start_date"]
data["end_date"] = request.form["end_date"]
data["n_images"] = request.form["n_images"]
elif request.method == "GET":
url += f"&start_date={today}"
images = requests.get(url).json()
return (images, data)
app = Flask(__name__)
@app.route("/", methods = ["POST", "GET"])
def index():
images, data = getData()
return render_template("viewer/base.jinja", images=images, data=data)
if __name__ == "__main__":
host = "127.0.0.1"
port = 5000
debug = True
app.run(host, port, debug)