aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-06 23:52:32 +1300
committerArslaan Pathan <[email protected]>2026-10-06 23:52:32 +1300
commit6d27aae18ed7e53928592575ee29ce182d7d1034 (patch)
tree608cf39a016b6ed5806d47d46e5cc94616f8f911 /main.py
parentb41e5288d7b8839b1ce0448489c365b243a8d00d (diff)
downloadremote-automation-6d27aae18ed7e53928592575ee29ce182d7d1034.tar.xz
remote-automation-6d27aae18ed7e53928592575ee29ce182d7d1034.zip
basic auth
Diffstat (limited to 'main.py')
-rw-r--r--main.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/main.py b/main.py
index c8d1e67..aa8c813 100644
--- a/main.py
+++ b/main.py
@@ -1,17 +1,35 @@
from evdev import InputDevice, list_devices, ecodes
-from urllib.request import urlopen
+from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
+from dotenv import load_dotenv
SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-", 0x101: "app", 0x154: "1", 0x110: "stop", 0x14b: "skip", 0x155: "epg", 0x119: "web", 0x15f: "setting", 0x15a: "dtv"}
device = None
last = 0x00
+load_dotenv("/home/arslaan/remote-automation/.env")
+
+HOMELAB_USERNAME = os.environ["HOMELAB_USERNAME"]
+HOMELAB_PASSWORD = os.environ["HOMELAB_PASSWORD"]
+
def homelab_request(request: str):
url = f"http://192.168.1.96/automate/{request}"
+ credentials = f"{HOMELAB_USERNAME}:{HOMELAB_PASSWORD}"
+ encoded_credentials = base64.b64encode(
+ credentials.encode()
+ ).decode()
+
+ req = Request(
+ url,
+ headers={
+ "Authorization": f"Basic {encoded_credentials}",
+ },
+ )
+
try:
- with urlopen(url, timeout=5) as resp:
+ with urlopen(req, timeout=5) as resp:
print(f"homelab request {request} response {resp.status}")
print(resp.read().decode())