-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
105 lines (73 loc) · 2.81 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import json
from flask import Flask, render_template, request, redirect, url_for, jsonify, Response
import urllib.parse
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route("/api/get_vacation_data")
def get_vacation_data():
filename = os.path.join(app.static_folder, 'vacations.json')
with open(filename) as vacation_file:
vacation_data = json.load(vacation_file)
return jsonify(vacation_data)
@app.route("/api/add_vacation_data", methods = ['GET','POST'])
def add_vacation_data():
data_json=request.get_json()
filename = os.path.join(app.static_folder, 'vacations.json')
with open(filename) as file:
vacation_data_add = json.load(file)
vacation_data_add.append(data_json)
with open(filename, 'w') as file:
json.dump(vacation_data_add, file, indent=4)
return jsonify(vacation_data_add)
@app.route("/api/remove_vacation_data", methods = ['GET','POST'])
def remove_vacation_data():
data_json=request.get_json()
filename = os.path.join(app.static_folder, 'vacations.json')
with open(filename) as file:
vacation_data_remove = json.load(file)
vacation_data_remove.remove(data_json)
with open(filename, 'w') as file:
json.dump(vacation_data_remove, file, indent=4)
return jsonify(vacation_data_remove)
@app.route("/api/get_events_data")
def get_events_data():
filename = os.path.join(app.static_folder, 'events.json')
with open(filename) as event_file:
event_data = json.load(event_file)
return jsonify(event_data)
@app.route("/api/add_events_data", methods = ['GET','POST'])
def add_events_data():
data_json=request.get_json()
filename = os.path.join(app.static_folder, 'events.json')
with open(filename) as file:
event_data_add = json.load(file)
event_data_add.append(data_json)
with open(filename, 'w') as file:
json.dump(event_data_add, file, indent=4)
return jsonify(event_data_add)
@app.route("/api/remove_events_data", methods = ['GET','POST'])
def remove_events_data():
data_json=request.get_json()
filename = os.path.join(app.static_folder, 'events.json')
with open(filename) as file:
event_data_remove = json.load(file)
event_data_remove.remove(data_json)
with open(filename, 'w') as file:
json.dump(event_data_remove, file, indent=4)
return jsonify(event_data_remove)
@app.route("/api/edit_events_data", methods = ['GET','POST'])
def edit_events_data():
data_json=request.get_json()
filename = os.path.join(app.static_folder, 'events.json')
with open(filename) as file:
event_data_edit = json.load(file)
event_data_edit[data_json['n']]['color']=data_json['color']
event_data_edit[data_json['n']]['text']=data_json['text']
with open(filename, 'w') as file:
json.dump(event_data_edit, file, indent=4)
return jsonify(event_data_edit)
if __name__ == '__main__':
app.run(debug=True)