Last active
January 4, 2023 16:30
-
-
Save bbelderbos/f55ea99b767afa4ba0766a38b39e5b1f to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> | |
<script defer src="https://pyscript.net/latest/pyscript.js"></script> | |
</head> | |
<body> | |
<h1>Time left till New Year:</h1> | |
<h2 id="showtime"></h2> | |
<py-config> | |
packages = ["python-dateutil"] | |
</py-config> | |
<py-script> | |
import asyncio | |
from datetime import datetime as dt | |
from dateutil.relativedelta import relativedelta | |
ny = dt(dt.now().year + 1, 1, 1, 0, 0, 0) | |
async def main(): | |
while True: | |
td = relativedelta(ny, dt.now()) | |
output = ( | |
f"{td.months} months {td.days} days {td.hours} hours " | |
f"{td.minutes} minutes {td.seconds} seconds" | |
) | |
Element('showtime').write(output) | |
await asyncio.sleep(1) | |
asyncio.ensure_future(main()) | |
</py-script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment