Finalize project

This commit is contained in:
2021-06-18 15:29:43 +02:00
parent cf7bb3b853
commit 22e06ba6a3
129 changed files with 3 additions and 434 deletions
+8
View File
@@ -0,0 +1,8 @@
FROM python:3.8-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV PORT 5003
EXPOSE 5003
ENTRYPOINT [ "python" ]
CMD [ "x_way_server.py" ]
+6
View File
@@ -0,0 +1,6 @@
# Super Lightweight Flask Web Server
* `pip install requirements.txt`
* `python x_way.py`
* `http://127.0.0.1:5000` -> `Hello World`
* `http://127.0.0.1:5000/api1` -> `api1`
* `http://127.0.0.1:5000/api2` -> `api2`
@@ -0,0 +1,6 @@
flask==1.1.4
Flask-Cors
requests
Flask-PyMongo
jsonify
flask_restx
@@ -0,0 +1,96 @@
import flask
import flask_restx
import requests
from bson import json_util
from flask import Flask, jsonify
from flask_cors import CORS
from flask import request
import json
app = Flask(__name__)
CORS(app)
api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1")
API = flask_restx.Api(api_bp)
app.register_blueprint(api_bp)
NAMESPACE = API.namespace("resources")
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
EVENT_STORE_URL = 'http://eventstore:5001/api/keys/'
@NAMESPACE.route('/car_events', doc={'description': 'Get most current car event for specific car'})
class CarsEvents(flask_restx.Resource):
@NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car',
'type': 'String', 'default': '5GZCZ43D13S812715'}})
@NAMESPACE.response(200, 'Success')
def get(self):
vin = request.args.get('vin')
try:
response = requests.get(EVENT_STORE_URL + 'DAF:' + vin + '/0/')
cars = json.loads(response.text)
except requests.exceptions.ConnectionError as e:
print("Is the EVENT_STORE_URL running and reachable?")
raise e
return jsonify(cars)
@NAMESPACE.route('/traffic_light_events', doc={'description': 'Get most current traffic light event'
'for specific traffic light'})
class TrafficLightEvents(flask_restx.Resource):
@NAMESPACE.doc(params={'id': {'description': 'Unique ID of traffic light',
'type': 'int', 'default': '1'}})
@NAMESPACE.response(200, 'Success')
def get(self):
id = request.args.get('id')
try:
response = requests.get(EVENT_STORE_URL + 'TL:' + id + '/0/')
traffic_lights = json.loads(response.text)
except requests.exceptions.ConnectionError as e:
print("Is the EVENT_STORE_URL running and reachable?")
raise e
return jsonify(traffic_lights)
@NAMESPACE.route('/cars', doc={'description': 'Get entity details for all cars'})
class Car(flask_restx.Resource):
@NAMESPACE.response(200, 'Success')
def get(self):
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 jsonify(cars)
@NAMESPACE.route('/traffic_lights', doc={'description': 'Get entity details for all traffic lights'})
class TrafficLights(flask_restx.Resource):
@NAMESPACE.response(200, 'Success')
def get(self):
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 jsonify(traffic_lights)
if __name__ == '__main__':
app.run('0.0.0.0', 5004)