hereyougo 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hereyougo/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """A tiny client for the HereYouGo notification service."""
2
+
3
+ from ._client import notify
4
+
5
+ __all__ = ["notify"]
6
+ __version__ = "0.0.2"
hereyougo/_client.py ADDED
@@ -0,0 +1,51 @@
1
+ """HTTP client for the HereYouGo notification service."""
2
+
3
+ import json
4
+ import os
5
+ from typing import Optional
6
+ import urllib.request
7
+
8
+ try:
9
+ from ._server import HOST, PORT # generated at build time by setup.py
10
+ except ImportError: # source checkout or editable install
11
+ HOST = PORT = None
12
+
13
+
14
+ def notify(message: str, *, user_id: Optional[str] = None, timeout: float = 10) -> None:
15
+ """Send *message* through the HereYouGo server.
16
+
17
+ The server address is baked in at build time from ``HEREYOUGO_VM_IP`` and
18
+ ``HEREYOUGO_BOT_PORT``; the same environment variables override it at run
19
+ time. The recipient ID can be passed explicitly or read from
20
+ ``HEREYOUGO_USER_ID``. When ``NOTIFY_TOKEN`` is set, it is sent as a
21
+ bearer token.
22
+
23
+ Network and HTTP errors from :mod:`urllib` are intentionally propagated.
24
+ """
25
+ host = os.environ.get("HEREYOUGO_VM_IP") or HOST
26
+ port = os.environ.get("HEREYOUGO_BOT_PORT") or PORT
27
+ if not host or not port:
28
+ raise RuntimeError(
29
+ "HereYouGo server is not configured: set HEREYOUGO_VM_IP and "
30
+ "HEREYOUGO_BOT_PORT"
31
+ )
32
+
33
+ user_id = user_id or os.environ.get("HEREYOUGO_USER_ID")
34
+ if not user_id:
35
+ raise RuntimeError(
36
+ "HereYouGo recipient is not configured: pass user_id or set "
37
+ "HEREYOUGO_USER_ID"
38
+ )
39
+
40
+ headers = {"Content-Type": "application/json"}
41
+ token = os.environ.get("NOTIFY_TOKEN")
42
+ if token:
43
+ headers["Authorization"] = f"Bearer {token}"
44
+
45
+ request = urllib.request.Request(
46
+ f"http://{host}:{port}/notify",
47
+ data=json.dumps({"user_id": user_id, "text": message}).encode("utf-8"),
48
+ headers=headers,
49
+ method="POST",
50
+ )
51
+ urllib.request.urlopen(request, timeout=timeout).close()
hereyougo/_server.py ADDED
@@ -0,0 +1,2 @@
1
+ HOST = '136.114.2.197'
2
+ PORT = 8000
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: hereyougo
3
+ Version: 0.0.2
4
+ Summary: Send a Telegram notification from your Python code
5
+ Author: KiShmakov
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+
10
+ # HereYouGo
11
+
12
+ A tiny, dependency-free client for sending messages directly from your Python
13
+ code:
14
+
15
+ ```python
16
+ import hereyougo
17
+
18
+ hereyougo.notify("Training finished", user_id="my-notification-id")
19
+ ```
20
+
21
+ Network and HTTP errors are raised to the caller. The default request timeout is
22
+ 10 seconds and can be changed with
23
+ `hereyougo.notify(message, user_id="my-id", timeout=30)`. The recipient may
24
+ also be set with the `HEREYOUGO_USER_ID` environment variable.
@@ -0,0 +1,7 @@
1
+ hereyougo/__init__.py,sha256=DmBlCm-h1p8bb_QczLOzATlDWS3alIeUdTXNKytKLTQ,133
2
+ hereyougo/_client.py,sha256=PAq8OGBQ1zIbUFemPoJ8KhpWeWLCH_roBjJ2AkZQ644,1782
3
+ hereyougo/_server.py,sha256=kxGQbEMb163lJbeHAbB7yywAjdu1m4h6jFb83D-5nG8,35
4
+ hereyougo-0.0.2.dist-info/METADATA,sha256=Iq4oazXLHzo5XEfR9mTP2Tb78WmigrADiXMD1W-Ieyw,662
5
+ hereyougo-0.0.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ hereyougo-0.0.2.dist-info/top_level.txt,sha256=1yl6XI_NOB3wsOkqXizpjEyjYxZIU783dX7g0a7DYLc,10
7
+ hereyougo-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ hereyougo