Afternoon all - Just received my Tidbyt and very impressed…
This could be a stupid question - i have got the Bitcoin example running, i have edited it to pull in a Json file from the UK Met Office, this returns a string. I cant seem to get it running - with an edit in the bitcoin example i get the error 'expected int, got string - current code below - feels close but no cigar. So the Q is - how do it pull in a string from Json and render the output?
It looks like you are assigning your JSON value to a variable name render which I think would conflict with the render module that is also imported as render.
Try something like this:
load("render.star", "render")
load("http.star", "http")
def main():
met = http.get("this goes to my metoffice data key").json()
amount = met["RegionalFcst"]["FcstPeriods"]["Period"]["0"]["$"]
return render.Root(
child = render.Text(content = amount)
)
Starlark’s JSON module will do some type conversion, I wonder if the value is being converted on you. I’d recommend printing met and inspecting the response to check that.
If it is an int, you can cast an int to a string like this: str(amount)
Thanks for the replies - almost there - print works, so the Json is correct - next error is
Error: too many arguments for format string
From print:
A dry night for most. Long clear spells are likely overnight, although some patchy cloud is possible at times, especially near some Norfolk coasts with chance of a shower. Feeling cold with brisk winds continuing. Strong coastal winds Frost inland. Minimum Temperature -1C.
2022/01/04 20:09:31 error loading applet: error running script: Traceback (most recent call last):
bitcoin.star:15:40: in main
Error: too many arguments for format string