So I am trying to modify a code I had seen for a game… This is just a snippet of a larger code. I found it interesting though, this code uses OCR, it takes a screenshot and uploads a general overview to discord with the use of webhooks. I found out that the system it used was by reading my system (computer) time… I want to change this to a simpler way to create a loop to execute this part every “x” minutes. It reads for the system time and every time this includes either 300, 301, 302, 303 or 304 then it executes the function. I am having a little bit of trouble changing this to a simple time.sleep() function. I don’t know if it is related to the rest of the code influencing but this is the snippet:
#IF LOGS ARE OPEN CHECK SYSTEM TIME, IF SYSTIME = THESE TIMES PERFORM LOG OVERVIEW
if tribe:
#EG 950 = 9m:50s
if str(300) in str_time or str(301) in str_time
or str(302) in str_time or str(303) in str_time
or str(304) in str_time:
ScreenGrab()
#CAN ADD A PRECHECK TO DETERMINE WHERE WE ARE ON THE ARK MENU (RECONNECT)
findcompare(im)
compare(im, roles)
#DELAY BETWEEN SCANS
time.sleep(1.9)
return
Does anyone sees any obvious change needed to be made that I missed? Appreciate any help.
I tried changing it to the following but it seems to apply the cooldown to a rather different part of the code.
#IF LOGS ARE OPEN CHECK SYSTEM TIME, IF SYSTIME = THESE TIMES PERFORM LOG OVERVIEW
if tribe:
#EG 950 = 9m:50s
time.sleep(60)
ScreenGrab()
#CAN ADD A PRECHECK TO DETERMINE WHERE WE ARE ON THE ARK MENU (RECONNECT)
findcompare(im)
compare(im, roles)
#DELAY BETWEEN SCANS
time.sleep(1.9)
return
This is what seems to be getting the cooldown:
def startup():
checkRunning()
#GETS SYSTEM TIME FOR USE IN LOG OVERVIEW
timestamp = time.time()
date_time = datetime.fromtimestamp(timestamp)
str_time = date_time.strftime("%M%S")
#TAKES SCREENSHOT OF ARK (REGARDLESS OF IF THE WINDOW IS ACTIVE OR NOT)
try:
logger.info("Taking SS")
Plus it is also sending 2 quick updates rather than 1 for some reason:
def LogHook():
if "https" in log_urls:
try:
#SETS THE WEBHOOK/MESSAGE
content = (f"**Quick Update** - {who}")
#SENDS THE REPORT TO DISCORD WEBHOOK
webhook = DiscordWebhook(url=log_urls, content=content)
with open("Log Update.png", "rb") as f:
webhook.add_file(file=f.read(), filename='Log Update.jpg')
webhook.execute()
logger.debug("Overview Updated")
endoffunc()
except Exception as e:
logger.error(f"Log Overview Failed", e)
If this is not understandable I can share the rest of the code but I don’t want to get the post full of code that might not be necessary.
1