-
Notifications
You must be signed in to change notification settings - Fork 7
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
0 parents
commit a51cf09
Showing
7 changed files
with
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.env | ||
README.md | ||
LICENSE | ||
.github | ||
.git | ||
.dockerfileexample |
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,110 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
torurl.py | ||
proxysite.py | ||
.dockerfileexample | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
.vercel | ||
.space |
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,9 @@ | ||
FROM python:3.8.10 | ||
ENV PYTHONUNBUFFERED 1 | ||
RUN pip install --upgrade pip | ||
RUN pip3 install requests python-dotenv websocket-client | ||
ENV GOTIFY_HOST=push.example.com | ||
ENV GOTIFY_TOKEN=XXXXXXXXXXXX | ||
ENV NTFY_HOST=https://ntfy.sh/gotify | ||
COPY gtfy.py /usr/bin | ||
CMD ["python3", "/usr/bin/gtfy.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,22 @@ | ||
# Copyright (c) 2023 sanweb.info | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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,86 @@ | ||
# GTFY 🚀 | ||
|
||
Gotify to `Ntfy.sh` forwarder | ||
|
||
Forward Gotify Push Messages 🚀 to `Ntfy.sh` Push server by using websocket 🛸 | ||
|
||
using Gotify stream to Listen the Gotify Push Notifications via websocket Connection and Froward it to Ntfy Push server. | ||
|
||
## Setup | ||
|
||
```sh | ||
git clone https://github.com/sanwebinfo/gtfy-listener | ||
cd gtfy-listener | ||
|
||
## local test | ||
## install packages | ||
pip install -r requirements.txt | ||
touch .env | ||
``` | ||
|
||
- Env File `.env` | ||
|
||
```sh | ||
NTFY = "<NTFY Push server URL>" | ||
GOTIFY_HOST = "<Python Cricket score API>" | ||
GOTIFY_TOKEN = "<GOTIFY CLIENT TOKEN>" | ||
|
||
## test | ||
python3 gtfy.py | ||
|
||
``` | ||
|
||
## Docker 🐬 | ||
|
||
Keep Running Python the Script in Docker forever | ||
|
||
- Update the `.dockerfile` before build - Replace example `ENV` with yours | ||
|
||
```sh | ||
FROM python:3.8.10 | ||
ENV PYTHONUNBUFFERED 1 | ||
RUN pip install --upgrade pip | ||
RUN pip3 install requests python-dotenv websocket-client | ||
ENV GOTIFY_HOST=push.example.com | ||
ENV GOTIFY_TOKEN=XXXXXXXXXXXX | ||
ENV NTFY_HOST=https://ntfy.sh/gotify | ||
COPY gtfy.py /usr/bin | ||
CMD ["python3", "/usr/bin/gtfy.py"] | ||
``` | ||
|
||
```sh | ||
|
||
## Build image | ||
docker build . -t="gtfy-listener" | ||
|
||
## List the image | ||
docker image ls | ||
|
||
## Create and Test Container | ||
docker run -d --name gtfy gtfy-listener | ||
docker container ps | ||
docker stop (containerID) | ||
|
||
## Run the container forever | ||
docker run -d --restart=always --name gtfy gtfy-listener | ||
|
||
## List Hidden container if error exists | ||
docker ps -a | ||
|
||
## other commands | ||
docker logs (containerID) | ||
docker stop (containerID) | ||
docker rm (containerid) | ||
docker docker rmi (imageid) | ||
docker image prune | ||
docker builder prune --all -f | ||
docker system prune --all | ||
``` | ||
|
||
## Inspiration | ||
|
||
Pushtify (Gotify to Pushover forwarder) - <https://github.com/sebw/pushtify/tree/main> | ||
|
||
## LICENSE | ||
|
||
MIT |
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,43 @@ | ||
from dotenv import load_dotenv | ||
import websocket | ||
import json | ||
import os | ||
import requests | ||
|
||
load_dotenv() | ||
|
||
ntfy_host = os.environ["NTFY_HOST"] | ||
gotify_host = os.environ['GOTIFY_HOST'] | ||
gotify_token = os.environ['GOTIFY_TOKEN'] | ||
|
||
|
||
def on_message(ws, message): | ||
msg = json.loads(message) | ||
querystring = {"title": msg['title'], "message": msg['message']} | ||
headers = { | ||
"Priority": "default", | ||
} | ||
response = requests.request( | ||
"POST", ntfy_host, headers=headers, params=querystring) | ||
print("websocket: " + message + "\n" + "Ntfy: " + response.text) | ||
|
||
|
||
def on_error(ws, error): | ||
print(error) | ||
|
||
|
||
def on_close(ws, close_status_code, close_msg): | ||
print("Connection closed") | ||
|
||
|
||
def on_open(ws): | ||
print("Opened Gotify websocket connection") | ||
|
||
|
||
if __name__ == "__main__": | ||
wsapp = websocket.WebSocketApp("wss://" + str(gotify_host) + "/stream", header={"X-Gotify-Key": str(gotify_token)}, | ||
on_open=on_open, | ||
on_message=on_message, | ||
on_error=on_error, | ||
on_close=on_close) | ||
wsapp.run_forever() |
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,3 @@ | ||
requests==2.25.1 | ||
websocket-client=1.6.3 | ||
python-dotenv=1.0.0 |