mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2026-04-26 15:32:28 +02:00
Compare commits
5 Commits
f7b6ccb740
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f3903b3936 | |||
| 39f795bbb6 | |||
| f468a789e3 | |||
| 527fa97dc8 | |||
| 000b7d2f43 |
@@ -9,6 +9,7 @@ import requests
|
||||
import re
|
||||
import smtphelper
|
||||
import json
|
||||
import datetime
|
||||
|
||||
HTTP_NOT_FOUND = 404
|
||||
|
||||
@@ -174,6 +175,8 @@ if __name__ == "__main__":
|
||||
smtp_pass = args.smtp_pass or os.environ.get("SMTP_PASS")
|
||||
smtp_port = args.smtp_port or os.environ.get("SMTP_PORT")
|
||||
|
||||
polling_interval = int(os.environ.get("POLLING_INTERVAL_SECONDS") or 5)
|
||||
|
||||
first_run = True
|
||||
while args.loop or first_run:
|
||||
|
||||
@@ -209,6 +212,8 @@ if __name__ == "__main__":
|
||||
email_address = entry.get("email")
|
||||
|
||||
# send message #
|
||||
print(f"Sending: {method} {hash(str(title))} @ {datetime.datetime.now()}",
|
||||
file=sys.stderr)
|
||||
if method == "signal":
|
||||
pass
|
||||
elif method == "ntfy":
|
||||
@@ -228,7 +233,7 @@ if __name__ == "__main__":
|
||||
|
||||
# wait a moment #
|
||||
if args.loop:
|
||||
time.sleep(5)
|
||||
time.sleep(polling_interval)
|
||||
|
||||
# handle non-loop runs #
|
||||
first_run = False
|
||||
|
||||
@@ -67,7 +67,7 @@ class UserSettings(db.Model):
|
||||
"email_priority" : self.email_priority,
|
||||
"ntfy_priority" : self.ntfy_priority,
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DispatchObject(db.Model):
|
||||
|
||||
@@ -352,7 +352,6 @@ def smart_send_to_clients(path=None):
|
||||
if not dispatch_acces_token:
|
||||
dispatch_acces_token = flask.request.headers.get("Dispatcher-Token") or ""
|
||||
|
||||
print(path)
|
||||
if path:
|
||||
webhook_path = db.session.query(WebHookPaths).filter(WebHookPaths.path==path).first()
|
||||
if webhook_path:
|
||||
@@ -387,6 +386,8 @@ def smart_send_to_clients(path=None):
|
||||
|
||||
def save_in_dispatch_queue(persons, title, message, method, link=""):
|
||||
|
||||
now_str = str(datetime.datetime.now())
|
||||
print(f"Scheduling message to {abs(hash(str(persons)))} @ {now_str}", file=sys.stderr)
|
||||
|
||||
dispatch_secrets = []
|
||||
for p in persons:
|
||||
@@ -398,6 +399,15 @@ def save_in_dispatch_queue(persons, title, message, method, link=""):
|
||||
dispatch_secret = secrets.token_urlsafe(32)
|
||||
|
||||
master_method = "any"
|
||||
|
||||
# handle bytes input #
|
||||
def normalize(v):
|
||||
return v.decode("utf-8") if isinstance(v, bytes) else v
|
||||
|
||||
p.username = normalize(p.username)
|
||||
p.phone = normalize(p.phone)
|
||||
p.email = normalize(p.email)
|
||||
|
||||
obj = DispatchObject(username=p.username,
|
||||
phone=p.phone,
|
||||
email=p.email,
|
||||
@@ -440,7 +450,7 @@ def create_app():
|
||||
app.config["SUBSTITUTIONS"] = {}
|
||||
if os.path.isfile(substitution_config_file):
|
||||
with open(substitution_config_file) as f:
|
||||
app.config["SUBSTITUTIONS"] = yaml.safe_load(f)
|
||||
app.config["SUBSTITUTIONS"] = yaml.safe_load(f) or {}
|
||||
|
||||
print("Loaded subs:", substitution_config_file, app.config["SUBSTITUTIONS"], file=sys.stderr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user