Update image on each appearance?

I’ve tried to find an answer to this question, but I’m having a hard time.

I have a list of image urls, and I’d like to display a random image from that list each time the app appears on the Tidbyt’s screen. This works each time I render and push the webp to my device, but would it work as a community app? Would it essentially render and push for each user every time their Tidbyt displays the app?

Here’s my code. Thanks for any help you can offer.

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

# List of image URLs
IMAGE_URLS = [
    'https://static.wixstatic.com/media/8d9d58_ba65f333d6ef4d54afc7e7ee913add72~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_64b00993fed244da9aa0b0afc6b2aeb2~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_0775e4ab23794c9989f448709d19088a~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_98ebe54da5b94327b313f2487ed56b3d~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_d6d67b6dbf10488ab3c817944fc2cd91~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_7608a6ddadf74503ac4fa2a0b9138b3a~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_e00da2f8b24c476689cdf7a63f5e9e44~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_ee6e920410fb4630a17b166110bff68e~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_c1dbaac41f0d4fd99f50672e0032a7f0~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_1c7cbcd89f664647afecab588db23a52~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_a1ff72395760435c9b9ed506958491cc~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_09c728b734b1472bb515115e0f5cefbf~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_8e3f4717e88d4345b4383b988bc35695~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_676295f1338e4899ad56100fca874932~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_61bf95fb091749e39e0d898116a32d84~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_f093386ee49e4d78a44c7f189991aee6~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_cce7f4b848f44ca1ba74e474385457c6~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_994e66d185f54a9e9d5c2321495c5afa~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_d5f744b2b130404cb066e2b6a9e3f142~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_10b516aee21b48c1a35cafb2bdf5933d~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_5a7b4b6d1fbe47a48edb4787f1d06bb5~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_cae29ec69ea64a9381b93100ff700cd5~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_90bee90249754d8cba22ff471d6986fa~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_d462b9c404804d4b98a549689297acd1~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_60488187035943c5a88ba292fa3070c6~mv2.jpg',
    'https://static.wixstatic.com/media/8d9d58_0aa0c5f269fa4505b14415c010e9aa55~mv2.jpg',
]

def main(config):
    # Select a random image URL from the list
    selected_url = IMAGE_URLS[random.number(0, len(IMAGE_URLS) - 1)]

    # Fetch the image from the URL
    response = http.get(selected_url)
    if response.status_code != 200:
        fail("Failed to fetch image: " + selected_url)

    # Create an image component
    image_component = render.Image(
        src=response.body(),
        width=62,   # Adjust the width as needed
        height=30   # Adjust the height as needed
    )

    # Create a Box component to center the image
    box_component = render.Box(
        child=image_component,
        width=64,
        height=32,
        padding=1,  # Optional padding around the image
    )

    # Display the box with the centered image
    return render.Root(
        child=box_component
    )

# No additional schema needed unless you want user-configurable options

We don’t know exactly how often the script gets run on the tidbyt backend. But I would assume that the image gets displayed multiple times before the script gets run again. However, I saw that new hieroglyphics app was updating quite frequently. Try that one and see if it updates every cycle. If so then your app can probably do the same thing if in community. That said if you have a way to push yourself it might be better to just do that so you can maintain control of exactly how often it’s updated.

1 Like

Thanks for taking a look!
I downloaded and pushed a similar app (Random Peanuts Images) , and it behaved the same way: It would update each time I rendered and pushed, but after that the image would remain the same each time the app appeared in my rotation. It’s a shame that it’s not possible to test how this kind of app would actually behave in the wild, or maybe I’m missing something.

That’s because the app doesn’t run on the tidbyt, it just shows the rendered image. The app only actually gets executed during the render process. The image won’t change until you re-render.