Add basic repo structure, dependencies and first endpoint
This commit is contained in:
parent
f7b7566b6e
commit
ab4ee6a00a
|
@ -0,0 +1,3 @@
|
||||||
|
__pycache__/
|
||||||
|
db.json
|
||||||
|
*.egg-info
|
16
README.md
16
README.md
|
@ -6,6 +6,20 @@ Small webapp to track who was in which room at which time to backtrace potential
|
||||||
|
|
||||||
For Ideas and Progress see [Issues](https://git.fasttube.de/FaSTTUBe/ft-corona-tracker/issues).
|
For Ideas and Progress see [Issues](https://git.fasttube.de/FaSTTUBe/ft-corona-tracker/issues).
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
(Dev setup, prod setup not finished yet)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# clone, cd into repo
|
||||||
|
pip3 install -e .
|
||||||
|
python3 -m ftracker
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, query the endpoint at <http://localhost:5000/times>.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
Licensed under GNU GPL v3, see [LICENSE.md](https://git.fasttube.de/FaSTTUBe/ft-corona-tracker/src/branch/master/LICENSE.md) for details.
|
Licensed under GNU GPL v3, see [LICENSE.md](https://git.fasttube.de/FaSTTUBe/ft-corona-tracker/src/branch/master/LICENSE.md) for details.
|
||||||
|
|
||||||
Copyright (C) 2020 Oskar/FaSTTUBe
|
Copyright (C) 2020 Oskar/FaSTTUBe
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[global]
|
||||||
|
db_file = db.json
|
|
@ -0,0 +1,13 @@
|
||||||
|
Database Layout
|
||||||
|
===============
|
||||||
|
|
||||||
|
Default table
|
||||||
|
```
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'name': 'firstname-middlename-lastname',
|
||||||
|
'arrival': 'UTC-ISO-TIMESTAMP',
|
||||||
|
'departure': 'UTC-ISO-TIMESTAMP'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
|
@ -0,0 +1 @@
|
||||||
|
from .core import *
|
|
@ -0,0 +1,14 @@
|
||||||
|
from .core import *
|
||||||
|
|
||||||
|
# Start the flask server if run from terminal
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# Just allow everything to avoid the hassle when running locally.
|
||||||
|
@app.after_request
|
||||||
|
def add_headers(response):
|
||||||
|
response.headers['Access-Control-Allow-Origin'] = '*'
|
||||||
|
response.headers['Access-Control-Allow-Methods'] = '*'
|
||||||
|
response.headers['Access-Control-Allow-Headers'] = '*'
|
||||||
|
return response
|
||||||
|
|
||||||
|
app.run()
|
|
@ -0,0 +1,11 @@
|
||||||
|
# _________ _________________________ ________
|
||||||
|
# __/ ___/ __ __/´___/__ ____ __// / / // __ )____
|
||||||
|
# / /_ _/´__` /\__ \ / /___/ / / / / // __ |/´_ \
|
||||||
|
# _/ __/ / /_/ /___/ /_/ / _/ /__/ /_/ // /_/ // __/
|
||||||
|
# /_/ ___\__,_//____/ /_/ __/_/ \____//_____/_\___/
|
||||||
|
|
||||||
|
# Corona time tracker
|
||||||
|
|
||||||
|
VERSION = (0, 0, 1)
|
||||||
|
|
||||||
|
__version__ = '.'.join(map(str, VERSION))
|
|
@ -0,0 +1,20 @@
|
||||||
|
import sys, os
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
def findConfigFile():
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
return sys.argv[1]
|
||||||
|
elif os.path.isfile('config.ini'):
|
||||||
|
return 'config.ini'
|
||||||
|
elif os.path.isfile('/etc/ftracker/config.ini'):
|
||||||
|
return '/etc/ftracker/config.ini'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
configfile = findConfigFile()
|
||||||
|
|
||||||
|
if configfile:
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read(configfile)
|
||||||
|
else:
|
||||||
|
config = None
|
|
@ -0,0 +1,42 @@
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from .config import config
|
||||||
|
if not config:
|
||||||
|
print('No configuration file found.')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
from tinydb import TinyDB
|
||||||
|
db = TinyDB(config.get('global','db_file', fallback='/tmp/ftracker-db.json'), indent=4)
|
||||||
|
# TODO: Load name list if needed
|
||||||
|
|
||||||
|
|
||||||
|
from flask import Flask, request
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def get_root():
|
||||||
|
return "Error: No Endpoint selected. See docs/API.md for reference.", 404
|
||||||
|
|
||||||
|
@app.route('/arrival', methods=['POST'])
|
||||||
|
def post_time():
|
||||||
|
|
||||||
|
try:
|
||||||
|
payload = request.data.decode('UTF-8')
|
||||||
|
data = json.loads(payload)
|
||||||
|
except ValueError as e:
|
||||||
|
return 'Error: JSON decode error:\n' + str(e), 400
|
||||||
|
|
||||||
|
# TODO: JSON schema validation
|
||||||
|
# TODO: JSON content validation
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
db.insert({
|
||||||
|
'name': data['name'],
|
||||||
|
'arrival': now.isoformat(),
|
||||||
|
'departure': None
|
||||||
|
})
|
||||||
|
|
||||||
|
return 'OK', 200
|
|
@ -0,0 +1,30 @@
|
||||||
|
import setuptools as st
|
||||||
|
|
||||||
|
with open("README.md", "r") as f:
|
||||||
|
long_description = f.read()
|
||||||
|
|
||||||
|
with open('LICENSE.md') as f:
|
||||||
|
license_text = f.read()
|
||||||
|
|
||||||
|
st.setup(
|
||||||
|
name="ftracker",
|
||||||
|
version="0.1.0",
|
||||||
|
author="Oskar @ FaSTTUBe",
|
||||||
|
author_email="o.winkels@fasttube.de",
|
||||||
|
description="Small webapp to track who was in which room at which time to backtrace potential viral infections",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
url="https://git.fasttube.de/FaSTTUBe/ft-corona-tracker",
|
||||||
|
packages=st.find_packages(exclude=['tests', 'docs']),
|
||||||
|
install_requires=[
|
||||||
|
"flask",
|
||||||
|
"tinydb",
|
||||||
|
],
|
||||||
|
license=license_text,
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
python_requires='>=3.6',
|
||||||
|
)
|
Loading…
Reference in New Issue