-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
51 lines (31 loc) · 1.13 KB
/
server.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
#!flask/bin/python
from flask import Flask, jsonify, request, Response
import redis
# Crossdomain imports
from datetime import timedelta
from flask import make_response, request, current_app
from functools import update_wrapper
r = redis.StrictRedis(host='localhost', port=6379, db=0)
app = Flask(__name__)
# Retrieve a user's alarm time
@app.route('/alarms/<username>', methods=['GET', 'OPTIONS'])
def get_alarm(username=None):
time = r.get(username)
return jsonify({'time': time})
# Save a user's alarm time
@app.route('/alarms', methods=['POST', 'OPTIONS'])
def save_alarm():
data = request.data.split('&')
username = data[0].split('=')[1]
time = data[1].split('=')[1]
r.set(username, time)
return Response('success')
# Temporary local development solution for CORS
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
if __name__ == '__main__':
app.run(debug=True)