59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
from gpxInterpreter import GPXHandler
|
|
from dotenv import load_dotenv
|
|
from flask import Flask, send_from_directory, jsonify, request
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
Session: Session
|
|
app: any
|
|
|
|
def entry():
|
|
print("load environment")
|
|
load_dotenv()
|
|
|
|
print("create flask application")
|
|
app = Flask(__name__, static_folder='web/dist')
|
|
|
|
# TODO: all the sqlalchemy stuff should be moved out of app.py
|
|
Base = declarative_base()
|
|
|
|
def db_connect(connectionPath):
|
|
return create_engine(connectionPath, poolclass=NullPool)
|
|
|
|
Base.metadata.create_all(db_connect)
|
|
session = sessionmaker(bind=db_connect())()
|
|
|
|
# handler class for all gpx files
|
|
# handles parsing files and interacting with database
|
|
gpxHandler = GPXHandler(session)
|
|
|
|
app.run(debug=True)
|
|
|
|
# TODO: move functional parts out to api package if not handled by other classes
|
|
@app.route('/')
|
|
def serve_vue_app():
|
|
return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
@app.route("/route", method=['GET'])
|
|
def getRoute():
|
|
# TODO: will contact gpx handler to get geoJSON from
|
|
return "not implemented", 500
|
|
|
|
@app.route('/upload', methods=['POST'])
|
|
def uploadFile():
|
|
if 'file' not in request.files:
|
|
return "no file provided", 400
|
|
|
|
file = request.files['file']
|
|
if file.filename == '':
|
|
return "no file selected", 400
|
|
|
|
try:
|
|
gpx_handler = GPXHandler(file.stream)
|
|
gpx_handler.parse()
|
|
return "file stored succesfull", 200
|
|
except Exception as e:
|
|
return "error" + " " + str(e), 500
|
|
|
|
if __name__ == '__main__':
|
|
entry() |