mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2025-12-09 07:48:33 +01:00
wip:
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
*.swp
|
*.swp
|
||||||
|
*.sqlite
|
||||||
|
sqlite.db
|
||||||
instance/
|
instance/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
signal_targets.txt
|
signal_targets.txt
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class DispatchObject(db.Model):
|
|||||||
message = Column(String, primary_key=True)
|
message = Column(String, primary_key=True)
|
||||||
method = Column(String)
|
method = Column(String)
|
||||||
dispatch_secret = Column(String)
|
dispatch_secret = Column(String)
|
||||||
|
dispatch_error = Column(String)
|
||||||
|
|
||||||
@app.route('/get-dispatch-status')
|
@app.route('/get-dispatch-status')
|
||||||
def get_dispatch_status():
|
def get_dispatch_status():
|
||||||
|
|||||||
@@ -14,15 +14,23 @@ def signal_send(phone, message):
|
|||||||
'''Send message via signal'''
|
'''Send message via signal'''
|
||||||
cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone]
|
cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone]
|
||||||
p = subprocess.run(cmd)
|
p = subprocess.run(cmd)
|
||||||
|
# TODO check return code #
|
||||||
|
|
||||||
|
|
||||||
|
def report_dispatch_error(target, uid, error):
|
||||||
|
'''Report an error for a give dispatch'''
|
||||||
|
|
||||||
|
pass # TODO
|
||||||
|
|
||||||
def confirm_dispatch(target, uid):
|
def confirm_dispatch(target, uid):
|
||||||
|
|
||||||
'''Confirm to server that message has been dispatched and can be removed'''
|
'''Confirm to server that message has been dispatched and can be removed'''
|
||||||
|
|
||||||
response = requests.post(target + "/confirm-dispatch", json=[{ "uid" : uid }],
|
response = requests.post(target + "/confirm-dispatch", json=[{ "uid" : uid }],
|
||||||
auth=(args.user, args.password))
|
auth=(args.user, args.password))
|
||||||
|
|
||||||
if response.status_code not in [200, 204]:
|
if response.status_code not in [200, 204]:
|
||||||
print("Failed to confirm disptach with server for {} ({})".format(uid, response.text), file=sys.stderr)
|
print("Failed to confirm disptach with server for {} ({})".format(
|
||||||
|
uid, response.text), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -43,6 +51,7 @@ if __name__ == "__main__":
|
|||||||
if args.signal_cli_bin:
|
if args.signal_cli_bin:
|
||||||
signal_cli_bin = args.signal_cli_bin
|
signal_cli_bin = args.signal_cli_bin
|
||||||
|
|
||||||
|
# request dispatches #
|
||||||
response = requests.get(args.target + "/get-dispatch?method={}".format(args.method),
|
response = requests.get(args.target + "/get-dispatch?method={}".format(args.method),
|
||||||
auth=(args.user, args.password))
|
auth=(args.user, args.password))
|
||||||
|
|
||||||
@@ -50,9 +59,16 @@ if __name__ == "__main__":
|
|||||||
if response.status_code == HTTP_NOT_FOUND:
|
if response.status_code == HTTP_NOT_FOUND:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
# fallback check for status #
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
|
# track dispatches that were confirmed to avoid duplicate confirmation #
|
||||||
dispatch_confirmed = []
|
dispatch_confirmed = []
|
||||||
|
|
||||||
|
# track failed dispatches #
|
||||||
|
errors = dict()
|
||||||
|
|
||||||
|
# iterate over dispatch requests #
|
||||||
for entry in response.json():
|
for entry in response.json():
|
||||||
|
|
||||||
user = entry["person"]
|
user = entry["person"]
|
||||||
@@ -62,14 +78,20 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# send message #
|
# send message #
|
||||||
if entry["method"] == "signal":
|
if entry["method"] == "signal":
|
||||||
signal_send(phone, message)
|
uid, error = signal_send(phone, message)
|
||||||
else:
|
else:
|
||||||
print("Unsupported dispatch method {}".format(entry["method"]), sys=sys.stderr)
|
print("Unsupported dispatch method {}".format(entry["method"]),
|
||||||
|
sys=sys.stderr)
|
||||||
|
|
||||||
# confirm dispatch
|
# confirm dispatch
|
||||||
if not args.no_confirm:
|
if not args.no_confirm:
|
||||||
for uid in uid_list:
|
for uid in uid_list:
|
||||||
if uid not in dispatch_confirmed:
|
if uid not in dispatch_confirmed:
|
||||||
|
|
||||||
|
# confirm or report fail #
|
||||||
|
if errors[uid]:
|
||||||
|
report_dispatch_error(args.target, uid, errors[uid])
|
||||||
|
else:
|
||||||
confirm_dispatch(args.target, uid)
|
confirm_dispatch(args.target, uid)
|
||||||
dispatch_confirmed.append(uid)
|
dispatch_confirmed.append(uid)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user