fix: Try to run automation every 5 mins

This commit is contained in:
Nathan Woodburn 2024-03-15 14:59:07 +11:00
parent 171e891555
commit afd7ae2947
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -3,7 +3,7 @@ import account
import requests import requests
import threading import threading
import os import os
import datetime import time
APIKEY = os.environ.get("hsd_api") APIKEY = os.environ.get("hsd_api")
ip = os.getenv("hsd_ip") ip = os.getenv("hsd_ip")
@ -37,22 +37,21 @@ functions = {
} }
} }
started = 0 started = False
# Main entry point only lets the main function run every 5 mins # Main entry point only lets the main function run every 5 mins
def automation(params, authentication): def automation(params, authentication):
global started global started
now = datetime.datetime.now().timestamp()
# Add 5 mins if started:
now = now - 300 return {"Status": "Auto Renews running"}
if now < started: started = True
return {"Status": "Waiting before checking for new actions"}
started = datetime.datetime.now().timestamp()
threading.Thread(target=automations_background, args=(authentication,)).start() threading.Thread(target=automations_background, args=(authentication,)).start()
return {"Status": "Checking for actions"} return {"Status": "Started Auto Renews"}
# Background function to run the automations # Background function to run the automations
def automations_background(authentication): def automations_background(authentication):
while True:
print("Running automations") print("Running automations")
# Get account details # Get account details
account_name = account.check_account(authentication) account_name = account.check_account(authentication)
@ -79,3 +78,6 @@ def automations_background(authentication):
requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REDEEM"]]]}) requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REDEEM"]]]})
except Exception as e: except Exception as e:
print(e) print(e)
# Sleep for 5 mins before running again
time.sleep(300)