What?
More "For What?" 😆... it's related to last weekend and I missed the in place of requests library
Problems I encountered
Before I mention things I came across, NiceGUI is really nice to use, docs are adequate and certainly enough demos and examples to get you going.
Main issue I came across was the "" to call the function to pull a GET request. I set it to every 1 minute as I am impatient, will increase this at some point.
The out kept getting appended instead of being overwritten or refreshed. 🤔
After a number of trial and errors, I found I could use a decorator called @ui.refreshable on the function I'm called to set the text on the labels. And yes, I created 2 label objects as I wanted to see the number of people who registered for the event and the number of tickets registered. 🙌
ℹ️ The former could have registered for a team of 5, so that is why the number is smaller than the latter.
Anyway, as this was a teeny side project, there wasn't many big problems I encountered! Which is good news! 😆
Mick mentioned repl.it which I forgot about and I'm am still paying for its subscription; I was meaning to use it for writing content for coding workshops but I just didn't have the time, and many moons have passed.
This was my opportunity and I logged in and wow, things have improved loads, UIs certainly looked nicer.
So created a new Python replit, and realised they don't use .env and instead use secrets:
Now I can just have that open or check the status on my phone. 😎
You can check it out, it's not really style in any fancy, just the 2 bits of info I needed: , I'm still a big fan of it. 🥰
import json
import os
import httpx
from nicegui import ui
headers = { "Authorization" : os.getenv("Authorization"),
"Accept":"application/json"}
ENDPOINT = "https://api.tito.io/v3/"
GET = "irishgeeks/seasons-geekings-the-techie-charity-quiz"
REGISTRATION_CNT = ""
TICKETS_CNT = ""
@ui.refreshable
def get_info_from_tito():
r = httpx.get(ENDPOINT + GET,
headers=headers
)
data = r.content
json_data = json.loads(data)
REGISTRATION_CNT = json_data.get("event").get("registrations_count")
TICKETS_CNT = json_data.get("event").get("tickets_count")
label_reg = ui.label()
label_tix = ui.label()
ui.label(f'REGISTRATION_CNT: {REGISTRATION_CNT}').style('color: #6E93D6; font-size: 200%; font-weight: 300')
ui.label(f'TICKETS_CNT: {TICKETS_CNT}').style('color: #6E93D6; font-size: 200%; font-weight: 300')
ui.markdown('# Info from [SEASON\'S GEEKINGS TITO PAGE](https://ti.to/irishgeeks/seasons-geekings-the-techie-charity-quiz)')
get_info_from_tito()
ui.timer(120.0, lambda: get_info_from_tito.refresh())
ui.run()
SOCIAL SHARE CARD GENERATOR