commit
f4b23845b1
3 changed files with 106 additions and 0 deletions
Split View
Diff Options
@ -0,0 +1,34 @@ |
|||
|
|||
## Requirements |
|||
pip: |
|||
* wheel |
|||
* gunicorn |
|||
* flask |
|||
|
|||
|
|||
## Unit File |
|||
```shell |
|||
[Unit] |
|||
Description=Gunicorn instance for primemeat |
|||
After=network.target |
|||
|
|||
[Service] |
|||
User=maintenance |
|||
Group=www-data |
|||
WorkingDirectory=/path/to/project |
|||
Environment="PATH=/path/to/project/bin" |
|||
#remove --reload when site is ready |
|||
#reload restarts workers when code changes |
|||
ExecStart=/path/to/project/bin/gunicorn --reload --workers 3 --bind 0.0.0.0:8900 wsgi:app |
|||
|
|||
[Install] |
|||
WantedBy=multi-user.target |
|||
``` |
|||
|
|||
## Caddy |
|||
```shell |
|||
primemeat.some.domain.org { |
|||
root * /path/to/project |
|||
reverse_proxy localhost:8900 |
|||
} |
|||
``` |
@ -0,0 +1,67 @@ |
|||
from flask import Flask, request, jsonify |
|||
from flask_sqlalchemy import SQLAlchemy |
|||
import time |
|||
|
|||
app = Flask(__name__) |
|||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///primemeat.db" |
|||
|
|||
# DB |
|||
db = SQLAlchemy(app) |
|||
class Umsatz(db.Model): |
|||
id = db.Column('id', db.Integer, primary_key = True) |
|||
monat = db.Column(db.String(7)) |
|||
wert = db.Column(db.Integer) |
|||
|
|||
def __init__(self, monat, wert): |
|||
self.monat = monat |
|||
self.wert = wert |
|||
|
|||
@app.route("/") |
|||
def hello(): |
|||
db.create_all() |
|||
return "<h1 style='color:blue'>Hello, Prime Meat!<h1>" |
|||
|
|||
@app.route('/time') |
|||
def get_current_time(): |
|||
return jsonify({'time': time.time()}) |
|||
|
|||
@app.route("/api/umsatz", methods=["GET", "POST", "DELETE"]) |
|||
def umsatz(): |
|||
method = request.method |
|||
if (method.lower() == "get"): |
|||
umsatz = Umsatz.query.all() |
|||
return jsonify([{"id": i.id, "monat": i.monat, "wert": i.wert} for i in umsatz]) |
|||
elif (method.lower() == "post"): |
|||
try: |
|||
monat = request.json["monat"] |
|||
wert = request.json["wert"] |
|||
if (monat and wert): |
|||
try: |
|||
umsatz = Umsatz(monat, wert) |
|||
db.session.add(umsatz) |
|||
db.session.commit() |
|||
return jsonify({"success": True}) |
|||
except Exception as e: |
|||
return ({"error": e}) |
|||
else: |
|||
return jsonify({"error": "Invalid form"}) |
|||
except: |
|||
return jsonify({"error": "Invalid form"}) |
|||
elif (method.lower() == "delete"): |
|||
try: |
|||
uid = request.json["id"] |
|||
if (uid): |
|||
try: |
|||
umsatz = Umsatz.query.get(uid) |
|||
db.session.delete(umsatz) |
|||
db.session.commit() |
|||
return jsonify({"success": True}) |
|||
except Exception as e: |
|||
return jsonify({"error": e}) |
|||
else: |
|||
return jsonify({"error": "Invalid form"}) |
|||
except: |
|||
return jsonify({"error": "m"}) |
|||
|
|||
if __name__ == "__main__": |
|||
app.run(host='0.0.0.0') |
@ -0,0 +1,5 @@ |
|||
from project import app |
|||
|
|||
if __name__ == "__main__": |
|||
app.run() |
|||
|