Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import requests | ||
import json | ||
|
||
from ..config import USER_AGENT | ||
|
||
GOTIFY_MSG_URL = '{url}/message?token={token}' | ||
|
||
|
||
def notify(title, | ||
message, | ||
url, | ||
access_token, | ||
extras=None, | ||
priority=None, | ||
retcode=None): | ||
""" | ||
Required parameter: | ||
* ``url`` - The url of the gotify server | ||
* ``access_token`` - Your Gotify App access token | ||
Optional parameters: | ||
* ``extras`` - Additional data in json format sent along the message | ||
* ``priority`` - integer | ||
For more info, see: https://gotify.net/docs | ||
""" | ||
|
||
data = { | ||
'title': title, | ||
'message': message, | ||
} | ||
|
||
if priority is not None: | ||
data['priority'] = priority | ||
|
||
if extras is not None: | ||
data['extras'] = json.load(extras) | ||
|
||
headers = {'User-Agent': USER_AGENT} | ||
|
||
resp = requests.post(GOTIFY_MSG_URL.format(url=url, token=access_token), | ||
json=data, | ||
headers=headers) | ||
|
||
resp.raise_for_status() |