Skip to content

Commit 3bb8b6c

Browse files
authored
Update at-extender.py
Version 1.1.5 released Changelog 1.1.5: - Sleeptimer addon: "smart" Dynamisch an das verbleibende Datenvolumen angepasst: >10 GB -> 1-1,5 Std. Pause >5 GB -> 15-30 Min. Pause >3 GB -> 10-15 Min. Pause >2 GB -> 5-7 Min. Pause >1.2 GB -> 2.5-4 Min. Pause >1 GB -> 1-1.5 Min. Pause <1 GB -> Sofortiger neuer Durchlauf wir bedanken uns bei dem User: Wimboson für diese Idee. - Easteregg hinzugefügt
1 parent 33803de commit 3bb8b6c

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

at-extender.py

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
LOGIN_URL = "https://login.alditalk-kundenbetreuung.de/signin/XUI/#login/"
1919
DASHBOARD_URL = "https://www.alditalk-kundenportal.de/portal/auth/uebersicht/"
2020

21-
VERSION = "1.1.4" # Deine aktuelle Version
21+
VERSION = "1.1.5" # Deine aktuelle Version
2222

2323
REMOTE_VERSION_URL = "https://raw.githubusercontent.com/Dinobeiser/AT-Extender/main/version.txt" # Link zur Version
2424
REMOTE_SCRIPT_URL = "https://raw.githubusercontent.com/Dinobeiser/AT-Extender/main/at-extender.py" # Link zum neuesten Skript
@@ -56,6 +56,24 @@ def load_config():
5656

5757
TELEGRAM_URL = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
5858

59+
LAST_GB = 0.0
60+
61+
try:
62+
with open("state.json", "r") as f:
63+
data = json.load(f)
64+
if isinstance(data, dict) and "last_gb" in data:
65+
LAST_GB = float(data["last_gb"])
66+
else:
67+
raise ValueError("Ungültiges Format in state.json - setze zurück.")
68+
except Exception as e:
69+
try:
70+
with open("state.json", "w") as f:
71+
json.dump({"last_gb": 0.0}, f)
72+
except Exception as save_error:
73+
logging.error(f"Konnte 'state.json' nicht neu erstellen: {save_error}")
74+
75+
76+
5977
def send_telegram_message(message, retries=3):
6078
if TELEGRAM == "1":
6179
for attempt in range(retries):
@@ -128,6 +146,7 @@ def wait_and_click(page, selector, timeout=5000, retries=5):
128146
return False
129147

130148
def login_and_check_data():
149+
global LAST_GB
131150
with sync_playwright() as p:
132151
for attempt in range(3): # 3 Versuche, falls Playwright abstürzt
133152
try:
@@ -267,6 +286,14 @@ def login_erfolgreich(p):
267286
else:
268287
GB = float(value)
269288

289+
LAST_GB = GB
290+
291+
try:
292+
with open("state.json", "w") as f:
293+
json.dump({"last_gb": LAST_GB}, f)
294+
except Exception as e:
295+
logging.warning(f"⚠️ Fehler beim Speichern des GB-Werts: {e}")
296+
270297
logging.info(f"Aktuelles Datenvolumen: {GB:.2f} GB")
271298

272299

@@ -281,7 +308,11 @@ def login_erfolgreich(p):
281308
send_telegram_message(message)
282309

283310
else:
284-
send_telegram_message(f"{RUFNUMMER}: Noch {GB:.2f} GB übrig. Kein Nachbuchen erforderlich. ✅")
311+
interval = get_interval(config)
312+
send_telegram_message(f"{RUFNUMMER}: Noch {LAST_GB:.2f} GB übrig. Nächster Run in {interval} Sekunden. ✅")
313+
return interval
314+
315+
285316

286317
return # Erfolgreicher Durchlauf, keine Wiederholung nötig
287318

@@ -296,31 +327,52 @@ def login_erfolgreich(p):
296327
time.sleep(2)
297328
logging.error("Skript hat nach 3 Versuchen aufgegeben.")
298329

299-
def sleep_interval(config):
300-
mode = config.get("SLEEP_MODE", "random") # "fixed" oder "random"
301330

302-
if mode == "fixed":
331+
def get_smart_interval():
332+
if LAST_GB >= 10:
333+
return random.randint(3600, 5400)
334+
elif LAST_GB >= 5:
335+
return random.randint(900, 1800)
336+
elif LAST_GB >= 3:
337+
return random.randint(600, 900)
338+
elif LAST_GB >= 2:
339+
return random.randint(300, 450)
340+
elif LAST_GB >= 1.2:
341+
return random.randint(150, 240)
342+
elif LAST_GB >= 1.0:
343+
return random.randint(60, 90)
344+
else:
345+
return 60 # Fallback
346+
347+
348+
def get_interval(config):
349+
mode = config.get("SLEEP_MODE", "random")
350+
if mode == "smart":
351+
return get_smart_interval()
352+
elif mode == "fixed":
303353
try:
304-
interval = int(config.get("SLEEP_INTERVAL", 70)) # Sicherstellen, dass es ein int ist
354+
return int(config.get("SLEEP_INTERVAL", 90))
305355
except ValueError:
306-
logging.warning("⚠️ Ungültiger SLEEP_INTERVAL-Wert - setze auf Standard 90 Sekunden.")
307-
interval = 90
308-
309-
if interval < 60:
310-
print("⚠️ Intervall zu kurz, auf 90 Sekunden gesetzt.")
311-
interval = 90 # Mindestintervall von 90 Sekunden
312-
elif mode == "random":
313-
interval = random.randint(300, 500)
314-
else:
315-
print("⚠️ Ungültiger SLEEP_MODE, verwende Standard 'random'.")
316-
interval = random.randint(300, 500)
356+
return 90
357+
elif mode.startswith("random_"):
358+
try:
359+
_, range_str = mode.split("_", 1)
360+
min_val, max_val = map(int, range_str.split("-"))
317361

318-
logging.info(f"💤 Warte {interval} Sekunden...")
319-
time.sleep(interval)
362+
if min_val >= max_val:
363+
raise ValueError("Min muss kleiner als Max sein")
364+
return random.randint(min_val, max_val)
365+
366+
except Exception as e:
367+
return random.randint(300, 500)
368+
369+
else:
370+
return random.randint(300, 500)
320371

321372
if __name__ == "__main__":
322373
while True:
323-
check_for_update() # Ruft die Update-Funktion auf
374+
check_for_update()
324375
logging.info("Starte neuen Durchlauf...")
325-
login_and_check_data()
326-
sleep_interval(config)
376+
interval = login_and_check_data()
377+
logging.info(f"💤 Warte {interval} Sekunden...")
378+
time.sleep(interval)

0 commit comments

Comments
 (0)