You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
890 B

""" Simple flask app"""
from flask import Flask, request # type: ignore
import pymongo # type: ignore
from os import getenv
from json import loads
if getenv('MONGO_URL') is None:
raise EnvironmentError('MONGO_URL not set')
app = Flask(__name__)
db = pymongo.MongoClient(getenv('MONGO_URL')).test.col
@app.route('/', methods=['GET'])
def get_data():
data = []
for x in db.find():
del x['_id']
return {"data": data}
@app.route('/', methods=['POST'])
def add_data():
txt = request.get_data(as_text=True)
data = loads(txt)
return {'message': 'success', 'data': data}
except Exception as e:
return {
'message': 'error',
'data': txt,
'error': str(e)
if __name__ == '__main__':'', port=8080)