This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
forked from Nunie123/upstate_tech_cal_service
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
62 lines (50 loc) · 1.91 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
from urllib import response
from flask import Flask, Response, request
from flask_cors import CORS
import simplejson as json
from configparser import ConfigParser
import app_functions as func
from flask_restful import Api, Resource
# import config file to global object
config = ConfigParser()
config_file = 'config.ini'
config.read(config_file)
import logging
from logging.config import fileConfig
# instantiate flask app
app = Flask(__name__)
CORS(app)
app.config['SECRET_KEY'] = config.get('flask', 'secret_key')
fileConfig('logging_config.ini')
logger = logging.getLogger()
api = Api(app)
# representation decorator tells the app to route request to this method
# when the request Content-Type is application/json
# See https://flask-restful.readthedocs.io/en/latest/extending.html#content-negotiation
# for description of this decorator.
@api.representation('application/json')
def output_json(data, code, headers={"Content-Type": "application/json"}):
events_data = json.dumps(data)
resp = Response(events_data, status=code, headers=headers)
return resp
@api.representation('application/json+ld')
def output_json_ld(data, code, headers={"Content-Type": "application/json+ld"}):
events_data = func.format_json_ld(data)
events_data = json.dumps(events_data)
resp = Response(events_data, status=code, headers=headers)
return resp
class Event(Resource):
def get(self):
with open('all_meetings.json') as json_data:
events = json.load(json_data)
start_date, end_date = func.get_dates()
events = func.filter_events_by_date(events, start_date, end_date)
tags = request.args.get('tags', None)
if tags:
events = func.filter_events_by_tag(events, tags)
events.sort(key=lambda s: s['time'])
return events
# binds the resource Event, to the endpoint `/api/gtc`
api.add_resource(Event, '/api/gtc')
if __name__ == '__main__':
app.run()