commit
bbbec95b92
4 changed files with 24 additions and 27 deletions
10
README.md
10
README.md
|
@ -19,11 +19,11 @@ There is a special script to get started with the project. Just run it in the ro
|
||||||
|
|
||||||
This will create a virtual environment, install the necessary dependencies and will give you the option to seed the database.
|
This will create a virtual environment, install the necessary dependencies and will give you the option to seed the database.
|
||||||
|
|
||||||
If you are using a database other then sqlite you will first need to configure the correct uri to the database in the generated 'config.py' file.
|
If you are using a database other then sqlite you will first need to configure the correct URI to the database in the generated 'config.py' file.
|
||||||
Afterwards upgrade the database to the latest version using
|
Afterwards upgrade the database to the latest version using
|
||||||
|
|
||||||
cd app
|
cd app
|
||||||
python haldis.py db upgrade
|
python3 app.py db upgrade
|
||||||
|
|
||||||
You can now still seed the database by running
|
You can now still seed the database by running
|
||||||
|
|
||||||
|
@ -38,15 +38,15 @@ Activate the virtual environment using
|
||||||
|
|
||||||
Finally run the webserver with
|
Finally run the webserver with
|
||||||
|
|
||||||
python app/haldis.py runserver
|
python3 app/app.py runserver
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### Changing the database
|
### Changing the database
|
||||||
|
|
||||||
1. Update models located in 'app/models.py'
|
1. Update models located in 'app/models.py'
|
||||||
2. Run `python app/haldis.py db migrate` to create a new migration.
|
2. Run `python app/app.py db migrate` to create a new migration.
|
||||||
3. Apply the changes to the database using `python app/haldis.py db upgrade`
|
3. Apply the changes to the database using `python app/app.py db upgrade`
|
||||||
|
|
||||||
### Adding dependencies/libraries
|
### Adding dependencies/libraries
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Configuration(object):
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
SECRET_KEY = "<change>"
|
SECRET_KEY = "<change>"
|
||||||
SLACK_WEBHOOK = "<add url>"
|
SLACK_WEBHOOK = None
|
||||||
LOGFILE = "haldis.log"
|
LOGFILE = "haldis.log"
|
||||||
ZEUS_KEY = "tomtest"
|
ZEUS_KEY = "tomtest"
|
||||||
ZEUS_SECRET = "blargh"
|
ZEUS_SECRET = "blargh"
|
||||||
|
|
|
@ -22,30 +22,29 @@ def post_order_to_webhook(order_item) -> None:
|
||||||
remaining_minutes(order_item.stoptime),
|
remaining_minutes(order_item.stoptime),
|
||||||
url_for("order_bp.order", id=order_item.id, _external=True),
|
url_for("order_bp.order", id=order_item.id, _external=True),
|
||||||
)
|
)
|
||||||
webhookthread = WebhookSenderThread(message)
|
webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"])
|
||||||
webhookthread.start()
|
webhookthread.start()
|
||||||
|
|
||||||
|
|
||||||
class WebhookSenderThread(Thread):
|
class WebhookSenderThread(Thread):
|
||||||
def __init__(self, message: str) -> None:
|
def __init__(self, message: str, url: str) -> None:
|
||||||
super(WebhookSenderThread, self).__init__()
|
super(WebhookSenderThread, self).__init__()
|
||||||
self.message = message
|
self.message = message
|
||||||
|
self.url = url
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.slack_webhook()
|
self.slack_webhook()
|
||||||
|
|
||||||
def slack_webhook(self) -> None:
|
def slack_webhook(self) -> None:
|
||||||
js = json.dumps({"text": self.message})
|
if self.url:
|
||||||
url = app.config["SLACK_WEBHOOK"]
|
requests.post(url, json={"text": self.message})
|
||||||
if len(url) > 0:
|
|
||||||
requests.post(url, data=js)
|
|
||||||
else:
|
else:
|
||||||
app.logger.info(str(js))
|
print(self.message)
|
||||||
|
|
||||||
|
|
||||||
def remaining_minutes(value) -> str:
|
def remaining_minutes(value) -> str:
|
||||||
delta = value - datetime.now()
|
delta = value - datetime.now()
|
||||||
if delta.total_seconds() < 0:
|
if delta.total_seconds() < 0:
|
||||||
return "0"
|
return "0"
|
||||||
minutes, _ = divmod(delta.total_seconds(), 60)
|
minutes = delta.total_seconds() // 60
|
||||||
return "%02d" % minutes
|
return "%02d" % minutes
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from app import create_app
|
INTERP = os.path.expanduser("~/env/bin/python3")
|
||||||
|
|
||||||
INTERP = os.path.expanduser("~/env/bin/python")
|
|
||||||
if sys.executable != INTERP:
|
if sys.executable != INTERP:
|
||||||
os.execl(INTERP, INTERP, *sys.argv)
|
os.execl(INTERP, INTERP, *sys.argv)
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
|
from app import create_app
|
||||||
application = create_app()
|
application = create_app().app
|
||||||
|
|
||||||
# For running on the server with passenger etc
|
# For running on the server with passenger etc
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
application.run(port=8000)
|
application.run()
|
||||||
|
|
Loading…
Reference in a new issue