Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Last active January 4, 2023 16:30
Show Gist options
  • Save bbelderbos/f55ea99b767afa4ba0766a38b39e5b1f to your computer and use it in GitHub Desktop.
Save bbelderbos/f55ea99b767afa4ba0766a38b39e5b1f to your computer and use it in GitHub Desktop.
<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