Hi everyone,
I’m finally getting around to trying to make my first Tidbyt app, inspired by the arrival of my second Tidbyt (Gen 2). I have experience with Python, but haven’t programmed in Go/Starlark before, and this being literally my first day using the language, I’ve encountered an error I can’t seem to resolve after modifying a ‘lift and shift’ approach on a similar app I used to base my idea around.
As the title states, when I go to serve the app via Pixlet, I get an error saying that it received an indent (in line 20, the one referring to the time_zone variable).
Please see the code below and let me know what I am missing to resolve this indent error.
"""
Applet: DaysSinceLast
Summary: Days Since Last [Incident]
Description: Displays the days since the last incident entered into custom text box. Based on AccidentFreeDays by Robert Ison.
Author: Drew Tschetter
"""
load("humanize.star", "humanize")
load("math.star", "math")
load("render.star", "render")
load("schema.star", "schema")
load("time.star", "time")
DEFAULT_DATE_TIME = "2020-01-01T00:00:00Z"
DEFAULT_COLOR = "#EEFF33"
DEFAULT_TEXT = "the incident."
def main(config):
last_incident = time.parse_time(config.get("last_incident", DEFAULT_DATE_TIME))
time_zone = config.get("$tz", "US/Eastern") # Utilize special time_zone variable
todays_date = time.now().in_location(time_zone)
duration = todays_date - last_incident
days_since = math.round(duration.hours / 24)
if days_since < 0:
days_since = 0.0
day_or_days = "days"
if days_since == 1.0:
day_or_days = "day"
num_color = config.get("color", DEFAULT_COLOR)
message = config.get("text", DEFAULT_TEXT)
return render.Root(
render.Box(
render.Column(
cross_align = "center",
main_align = "center",
children = [
render.Text("%s" % humanize.float("#,###.", days_since), color = num_color, font = "6x13"),
render.Text("%s since" % day_or_days, color = "#ffffff", font = "tb-8"),
render.Text(message, color = "#ffffff", font = "tb-8"),
],
),
),
)
def get_schema():
return schema.Schema(
version = "1",
fields = [
schema.DateTime(
id = "last_incident",
name = "Last_incident",
desc = "Date of the last incident",
icon = "calendar",
),
schema.Text(
id = "text",
name = "Text",
desc = "Brief description of the incident",
icon = "font",
default = "the incident.",
),
schema.Color(
id = "color",
name = "Color",
desc = "Color of the incident-free duration number",
icon = "brush",
default = "#EEFF33",
),
],
)```