-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·97 lines (80 loc) · 2.93 KB
/
app.py
File metadata and controls
executable file
·97 lines (80 loc) · 2.93 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
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
#!/usr/bin/env python
from flask import Flask, render_template, redirect, url_for, abort, request
import time
import datetime
from workalendar.usa import *
from workalendar.europe import *
import json
import os
from security import SecurityRef
from schedule import CSchedule
app = Flask(__name__, static_url_path='/static')
app.config['SECRET_KEY'] ='OpenFin'
usaholidays = UnitedStates()
franceholidays = France()
greeceholidays = Greece()
ukholidays = UnitedKingdom()
def json_serial(obj):
if isinstance(obj, datetime.datetime):
serial = obj.isoformat()
return serial
raise TypeError("Type not Serializable")
if isinstance(obj, datetime.date):
serial = obj.isoformat()
return serial
raise TypeError("Type not Serializable")
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/views/<path:filename>')
def getView(filename):
return app.send_static_file('views/' + filename)
@app.route('/js/<path:filename>')
def getJsFile(filename):
return app.send_static_file('js/' + filename)
@app.route('/css/<path:filename>')
def getCssFile(filename):
return app.send_static_file('css/' + filename)
@app.route('/img/<path:filename>')
def getImgFile(filename):
return app.send_static_file('img/' + filename)
@app.route('/country/<string:iso>/<int:year>', methods=['GET'])
def country(iso, year):
result = []
if iso == 'USA':
for i in usaholidays.holidays(year):
result.append({ 'date': i[0], 'name': i[1]})
holiday = json.dumps(result,default=json_serial)
return holiday
elif iso == 'FRA':
for i in franceholidays.holidays(year):
result.append({ 'date': i[0], 'name': i[1]})
holiday = json.dumps(result,default=json_serial)
return holiday
elif iso == 'GRE':
for i in greeceholidays.holidays(year):
result.append({ 'date': i[0], 'name': i[1]})
holiday = json.dumps(result,default=json_serial)
return holiday
elif iso == 'GBR':
for i in ukholidays.holidays(year):
result.append({ 'date': i[0], 'name': i[1]})
holiday = json.dumps(result,default=json_serial)
return holiday
@app.route('/schedule/<string:type>/<int:id>', methods=['GET'])
def schedule(type, id):
securityinfo = SecurityRef().get(type,id)
print(securityinfo)
dates = CSchedule().get_schedule(securityinfo)
return json.dumps(list(dates), default=json_serial)
@app.route('/securityschedule/<string:type>/<int:id>', methods=['GET'])
def securityschedule(type, id):
return json.dumps(SecurityRef().get(type,id), default=json_serial)
@app.route('/cschedule', methods=['PUT', 'POST'])
def security():
input_params = json.loads(request.data)
result =CSchedule().get(input_params)
return json.dumps(result, default=json_serial)
if __name__ == '__main__':
port = int(os.environ.get("PORT", 8000))
app.run(host='0.0.0.0', port=8000, debug=True)