Polling of URL - Realtime Data

Hello Tidbyt community!

Just starting my dev journey, so forgive if obvious.

As a proof-of-concept, I just want my Tidbyt to poll (i.e. GET) the contents of a URL on a steady rhythm. Basically, “every 2 seconds, .GET() this URL, and display it”.

I followed the caching tutorial (in the bitcoin tracking example), and added ttl_seconds to my http.get(), thinking this is it.

Sadly , the Tidbyt only displays the text of the URL from the time I rendered the app onto the hardware. How can I get it to keep polling??

My code:

load("render.star", "render")
load("http.star", "http")

URL = "https://[some-url]/test.txt"

def main():
    rep = http.get(URL, ttl_seconds = 2)
    if rep.status_code != 200:
        fail("Rquest failed with status %d", rep.status_code)

    print(rep.body())

    return render.Root(
        child = render.Text(rep.body())
    )

Thanks, all!

I also may simply misunderstanding what’s possible. Upon further reading, it seems like maybe I’d have to either:

a) render & push on a loop (from some other computer)
or
b) publish my app on the community repo

… perhaps that’s the answer, and I’m in error about the fundamental architecture. Hopefully someone can set me straight!

Without publishing to community repo you must manually run pixlet ever 2 seconds yourself. That is the best way to control exactly how much time passes between two polls anyway since you can’t know exactly how often the script will get run when it’s controlled from the tidbyt servers. It might only get executed once every 5 seconds or 10 or 30 seconds. That exact number is not known AFAIK.

1 Like