This repository was archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (42 loc) · 1.38 KB
/
Copy pathmain.py
File metadata and controls
59 lines (42 loc) · 1.38 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
# app.py
import time
import gevent.monkey
import os
gevent.monkey.patch_all()
from flask import Flask, send_from_directory, jsonify, request
from flask_socketio import SocketIO
from mvg import get_departures
from owncloud import get_photos
from flask_cors import CORS
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
CORS(app)
socketio = SocketIO(app)
# Define the static directory
static_file_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static')
@app.route('/', methods=['GET'])
def serve_dir_directory_index():
return send_from_directory(static_file_dir, 'index.html')
@app.route("/api/mvg/<int:station>")
def rest_get_mvg(station):
response = dict()
walking_distance = request.args.get('walking_distance', default=8)
# hauptbahnhof is station with id 6
response["mvg"] = get_departures(station, walking_distance)
# return response
return jsonify(response)
@app.route("/api/photos")
def rest_get_photos():
response = dict()
response["photos"] = get_photos()
return jsonify(response)
@app.route("/api/welcome")
def rest_post_welcome():
socket_welcome_emit("Sebastian")
return ('', 204)
def socket_welcome_emit(name):
response = dict()
response['message'] = "Welcome " + name
socketio.emit('welcome', response, json=True)
if __name__ == '__main__':
socketio.run(app, debug=True, port=5003, host='0.0.0.0')