Last active
July 30, 2022 10:13
-
-
Save kpodp0ra/484ba68c54195dd5c2851c7237552ec5 to your computer and use it in GitHub Desktop.
Helper asynchronous function that waits until clock hits specified hour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import datetime | |
def wait_for_clock(hour, minute, result=None): | |
t = datetime.datetime.combine( | |
datetime.date.today(), | |
datetime.time(hour, minute) | |
) | |
tt = datetime.datetime.now() | |
if tt >= t: | |
t += datetime.timedelta(days=1) | |
delta = t - tt | |
delta_sec = delta.seconds + delta.microseconds * 0.000001 | |
return asyncio.sleep(delta_sec, result) | |
async def main(): | |
while True: | |
await wait_for_clock(8, 30) | |
print(1) | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment