Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevalicjus committed Jul 26, 2022
1 parent 8f54dff commit 4b248e7
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: nevalicjus
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: Report a bug
---

## Expected Behaviour
<!-- Tell us what do you think should've happened -->

## Observed Behaviour
<!-- Tell us what happens instead -->

## Steps to reproduce
<!-- Provide a link to a live example -->
<!-- or a set of steps to reproduce the bug. -->
1. Run command x
2. ...

## Context (Environment)
<!-- Operating System you are running the bot on, -->
<!-- Python and library versions, Invitebot version -->

## Possible Solution
<!-- Not obligatory, but suggest a fix / idea how to fix -->
<!-- the bug. Can include example code -->
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Feature request
about: Request a feature
---

## Description
<!-- Describe what your requested feature is, in as much detail as you can -->
<!-- If you're request is related to a problem, please describe it here -->


## Related Documentation
<!-- If possible, provide links to relevant documentation -->
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Maciej Bromirski

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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ntfpy

Wrapper for ntfy.sh processes
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=45",
"wheel"
]
build-backend = "setuptools.build_meta"
27 changes: 27 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[metadata]
name = ntfpy
version = 0.0.5
author = Nevalicjus
author_email = [email protected]
description = Ntfy.sh process wrapper
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/nevalicjus/ntfpy
project_urls =
Author = https://n3v.xyz
Bug Tracker = https://github.com/nevalicjus/ntfpy/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent

[options]
package_dir =
= src
packages = find:
python_requires = >=3.6
install_requires =
requests

[options.packages.find]
where = src
3 changes: 3 additions & 0 deletions src/ntfpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .send import send

from .subscribe import subscribe
31 changes: 31 additions & 0 deletions src/ntfpy/send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import requests
import base64

__all__ = (
'send'
)

def send(server, topic, message, auth = None, title = None, priority = None, tags = None, click = None, attach = None, actions = None, email = None, delay = None):
headers = {}
if auth != None:
auth_bytes = auth.encode('ascii')
b64_bytes = base64.b64encode(auth_bytes)
b64_s = b64_bytes.decode('ascii')
headers["Authorization"] = f"Basic {b64_s}"
if title != None:
headers["Title"] = title
if priority != None:
headers["Priority"] = priority
if tags != None:
headers["Tags"] = tags
if click != None:
headers["Click"] = click
if attach != None:
headers["Attach"] = attach
if actions != None:
headers["Actions"] = actions
if email != None:
headers["Email"] = email
if delay != None:
headers["Delay"] = delay
r = requests.post(f"{server}/{topic}", headers = headers, data = message)
22 changes: 22 additions & 0 deletions src/ntfpy/subscribe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
import base64
import json

__all__ = (
'subscribe'
)

async def subscribe(server, topic, auth = None):
if auth is None:
r = requests.get(f"{server}/{topic}/json", stream = True)
else:
auth_bytes = auth.encode('ascii')
b64_bytes = base64.b64encode(auth_bytes)
b64_s = b64_bytes.decode('ascii')
headers = {
"Authorization": f"Basic {b64_s}"
}
r = requests.get(f"{server}/{topic}/json", stream = True, headers = headers)
for l in r.iter_lines():
if l:
print(json.loads(l.decode('utf-8')))

0 comments on commit 4b248e7

Please sign in to comment.