forked from nesfit/fitcrack
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discord notifications - basic support
- Loading branch information
1 parent
67bd4bb
commit 3824beb
Showing
12 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ msgpack==1.0.4 | |
PyJWT==2.7.0 | ||
werkzeug==2.3.7 | ||
SQLAlchemy==2.0.20 | ||
apprise==1.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/src/src/api/fitcrack/endpoints/notifications/notifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import apprise | ||
|
||
from src.database.models import FcNotification, FcSettings, FcUser | ||
from src.database import db | ||
|
||
from src.api.fitcrack.lang import job_status_text_info_to_code_dict | ||
|
||
class Notification: | ||
def __init__(self, title, body): | ||
self.title = title | ||
self.body = body | ||
|
||
def notify(userId): | ||
settings = FcSettings.query.filter_by(user_id=userId).one() | ||
apobj = apprise.Apprise() | ||
|
||
if settings.discord_notifications: | ||
apobj.add(settings.discord_webhook_url) | ||
|
||
for user in FcUser.query.all(): | ||
new_notifications = FcNotification.query.filter(FcNotification.user_id == userId).filter(FcNotification.discord_sent == False) | ||
|
||
for notif in new_notifications: | ||
title = notif.source.name if notif.source else '<Removed Job>' | ||
body = title + ": " + job_status_text_info_to_code_dict[notif.new_value] | ||
print(title, body) | ||
|
||
apobj.notify(body=body) | ||
notif.discord_sent = True | ||
|
||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters