start time:
[[fetch]] files = ["./utils.py"] import utils display(utils.now()) from utils import now import asyncio async def foo(): while True: await asyncio.sleep(1) output = now() Element("outputDiv2").write(output) out3 = Element("outputDiv3") if output[-1] in ["0", "4", "8"]: out3.write("It's espresso time!") else: out3.clear() pyscript.run_until_complete(foo())
View Code

index.html

          
            <div class="font-mono">start time: <label id="outputDiv"></label></div>
            <div id="outputDiv2" class="font-mono"></div>
            <div id="outputDiv3" class="font-mono"></div>
            <py-config>
              [[fetch]]
              files = ["./utils.py"]
            </py-config>
            <py-script>
              from utils import now
              import asyncio

              async def foo():
                while True:
                  await asyncio.sleep(1)
                  output = now()
                  Element("outputDiv2").write(output)

                  out3 = Element("outputDiv3")
                  if output[-1] in ["0", "4", "8"]:
                    out3.write("It's espresso time!")
                  else:
                    out3.clear()

              pyscript.run_until_complete(foo())
            </py-script>
          
        

utils.py

          
            from datetime import datetime as dt

            def format_date(dt_, fmt="%m/%d/%Y, %H:%M:%S"):
                return f"{dt_:{fmt}}"

            def now(fmt="%m/%d/%Y, %H:%M:%S"):
                return format_date(dt.now(), fmt)

            def remove_class(element, class_name):
                element.element.classList.remove(class_name)

            def add_class(element, class_name):
                element.element.classList.add(class_name)