-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
37 lines (27 loc) · 924 Bytes
/
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
from flask import Flask, render_template, request
import json
import os
from google.protobuf.json_format import MessageToJson
import service
from service import railroad_client as client
app = Flask(__name__)
MAPS_API_KEY = os.getenv('MAPS_API_KEY')
if MAPS_API_KEY == None:
import secret
MAPS_API_KEY = secret.MAPS_API_KEY
@app.route('/')
def index():
cities = None
with open('cities.json') as f:
cities = json.loads(f.read())
return render_template('map.html', cities=cities, api_key=MAPS_API_KEY)
@app.route('/allLines')
def get_all_lines():
return MessageToJson(client.get_all_paths())
@app.route('/fetchSearchResults')
def perform_search():
source = request.args.get('source', '')
destination = request.args.get('destination', '')
return MessageToJson(client.perform_search(source, destination))
if __name__ == '__main__':
app.run(port=os.getenv('PORT', 5000))