From 0f044a1de7be89676251f6651eb37d16426be36e Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 9 Dec 2023 13:02:00 +0100 Subject: [PATCH] Init project --- Makefile | 5 +++++ main.py | 34 ++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 40 insertions(+) create mode 100644 Makefile create mode 100644 main.py create mode 100644 requirements.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc0773f --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +install: + pip install -r requirements.txt + +run: + FRITZ_PASSWORD=$$FRITZ_PASSWORD python main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..2358319 --- /dev/null +++ b/main.py @@ -0,0 +1,34 @@ +from itertools import count + +from fritzconnection import FritzConnection +from fritzconnection.core.exceptions import FritzServiceError +from fritzconnection.core.fritzconnection import os + + +def turn_of_wlan(fc): + result = [] + action = "SetEnable" + for n in count(1): + service = f"WLANConfiguration{n}" + try: + fc.call_action(service, action, NewEnable=False) + except FritzServiceError: + break + result.append(f"Turned off {service}") + return result + + +def main(address, password): + fc = FritzConnection(address=address, password=password) + for result in turn_of_wlan(fc): + print(f"{result}") + + +if __name__ == "__main__": + try: + password = os.environ["FRITZ_PASSWORD"] + except KeyError: + print("Error: FRITZ_PASSWORD environment variable not set.") + exit(1) + + main(address="192.168.178.1", password=password) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4166c88 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +fritzconnection==1.13.2