47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import requests
|
|
from bson import json_util
|
|
from flask import Flask
|
|
from flask_cors import CORS
|
|
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
|
|
|
|
|
@app.route('/')
|
|
def hello_world():
|
|
return 'Hello World'
|
|
|
|
|
|
@app.route('/api/v1/resources/cars', methods=['GET'])
|
|
def get_cars():
|
|
|
|
try:
|
|
response = requests.get(ENTITY_IDENT_URL + 'cars')
|
|
cars = response.json()['cursor']
|
|
|
|
except requests.exceptions.ConnectionError as e:
|
|
print("Is the entity_ident_server running and reachable?")
|
|
raise e
|
|
|
|
return json_util.dumps({'cursor': cars})
|
|
|
|
|
|
@app.route('/api/v1/resources/traffic_lights', methods=['GET'])
|
|
def get_traffic_lights():
|
|
|
|
try:
|
|
response = requests.get(ENTITY_IDENT_URL + 'traffic_lights')
|
|
traffic_lights = response.json()['cursor']
|
|
|
|
except requests.exceptions.ConnectionError as e:
|
|
print("Is the entity_ident_server running and reachable?")
|
|
raise e
|
|
|
|
return json_util.dumps({'cursor': traffic_lights})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run('0.0.0.0', 5004)
|