From d769f9f31f4f9c196d100857bb3b53698234c9bb Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 27 Aug 2022 00:34:50 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20added=20notification=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.json.md | 6 +++++- requirements.txt | 1 + src/index.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/config.json.md b/docs/config.json.md index f8a22f2..9023720 100644 --- a/docs/config.json.md +++ b/docs/config.json.md @@ -4,4 +4,8 @@ - `name` : Personal Name - `email` : Personal Mail - `secret_key` : Secret Key for Flask -- `xmr_address` : Monero Receive Address \ No newline at end of file +- `xmr_address` : Monero Receive Address +- `notify` : Notification Object +- - `gotify`: Gotify Object +- - - `token` : Gotify Token +- - - `host` : Gotify Host/Domain name \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a62cfdd..eb2547c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask gnupg +requests git+https://github.com/jmarya/htmlpy#egg=htmlpy \ No newline at end of file diff --git a/src/index.py b/src/index.py index 21374ff..6fdb30e 100644 --- a/src/index.py +++ b/src/index.py @@ -4,6 +4,7 @@ from config import CONFIG from os.path import exists import os import datetime +import requests import gnupg main_pages = Blueprint("main", __name__) @@ -38,6 +39,22 @@ def save_message(msg, name=""): f.write(msg) +def notify(msg, title=None): + try: + gotify_notification(msg, title) + except: + pass + + +def gotify_notification(msg, title=None): + token = CONFIG["notify"]["gotify"]["token"] + url = CONFIG["notify"]["gotify"]["host"] + requests.post( + f"https://{url}/message?token={token}", + {"title": title, "message": msg, "priority": "5"}, + ) + + # Message Sending Page @main_pages.route("/message", methods=["GET", "POST"]) def send_message(): @@ -48,6 +65,7 @@ def send_message(): if msg is not None: cipher = encrypt(msg) save_message(cipher, name) + notify(f"New Message from {name}") return redirect(request.url_root.replace("http", "https")) else: # Return Message Form