-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataFetcher.py
52 lines (38 loc) · 1.25 KB
/
dataFetcher.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
import pandas as pd
import json
from flask import Flask, request
from flask_cors import CORS
app = Flask(__name__)
cors = CORS(app)
df = pd.read_csv("resources/moonquakeData.csv")
@app.route("/getInfo", methods=["POST"])
def getInfo():
data = request.get_json()
data = df.loc[(df['Year'] == int(data["year"]))
& (df['Month'] == data["month"]) &
(df['Day'] == int(data["day"]))].to_dict()
for i in data:
data[i] = list(data[i].values())[0]
if data["Magnitude"] == -1:
data["Magnitude"] = None
return json.dumps(data)
@app.route("/getYear", methods=["POST"])
def getYear():
# Get input from the HTML form
return json.dumps({"years": list(set(df["Year"]))})
@app.route("/getMonthFromYear", methods=["POST"])
def getMonthFromYear():
data = request.get_json()
return json.dumps(
{"months": list(set(df.loc[df['Year'] == int(data["year"]), 'Month']))})
@app.route("/getDayFromMonthYear", methods=["POST"])
def getDayFromMonthYear():
data = request.get_json()
return json.dumps({
"days":
list(
set(df.loc[(df['Year'] == int(data["year"])) &
(df['Month'] == data["month"]), 'Day']))
})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=True)