You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a python script (part of a twitch bot) that will update the data if the current time is greater than the end time from the data. This works, but it fetches the data around 20 times instead of once. I fixed this by adding 20 seconds to the end time.
Here's my code:
asyncdeffetchdata():
splatnet_schedules="https://splatoon3.ink/data/schedules.json"log("Fetching new data from https://splatoon3.ink/...")
asyncwithaiohttp.ClientSession() assession:
asyncwithsession.get(splatnet_schedules) asresponse:
ifresponse.status==200:
bot.schedules=awaitresponse.json()
withopen('data/schedules.json', 'w') asfile:
json.dump(bot.schedules, file)
else:
log.error("Failed to retrieve schedules!")
# wait 5 mins before trying againawaitasyncio.sleep(5*60)
asyncdefrequest_loop():
# load data from file, or get new datawithopen('data/schedules.json', 'r') asfile:
try:
bot.schedules=json.load(file)
log("Loaded data from file.")
except:
awaitfetchdata()
# check if it's time to fetch new data every few secondswhileTrue:
nextrotation=datetime.datetime.fromisoformat(bot.schedules['data']['regularSchedules']['nodes'][0]['endTime'])
nextrotation+=datetime.timedelta(seconds=20)
ifdatetime.datetime.now(datetime.timezone.utc) >nextrotation:
awaitfetchdata()
awaitasyncio.sleep(1)
The text was updated successfully, but these errors were encountered:
I wrote a python script (part of a twitch bot) that will update the data if the current time is greater than the end time from the data. This works, but it fetches the data around 20 times instead of once. I fixed this by adding 20 seconds to the end time.
Here's my code:
The text was updated successfully, but these errors were encountered: