Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions apps/nws_live_forecast/nws_live_forecast.star
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DAY_LABELS = [
def main(config):
# Config
location = json.decode(config.get("location") or DEFAULT_LOCATION)
celsius = config.bool("celsius", False)

response = http.get(WEATHER_URL + location["lat"] + "," + location["lng"], ttl_seconds = 300)
if response.status_code != 200:
Expand All @@ -66,7 +67,7 @@ def main(config):
prevDay = day
days[len(days) - 1].append(period)

nowTemp = int(math.round(rightNow["temperature"]))
nowTemp = to_celsius(int(math.round(rightNow["temperature"])), celsius)
cols = [render.Column(
cross_align = "center",
children = [
Expand All @@ -80,7 +81,7 @@ def main(config):
if len(cols) >= MAX_DAYS_TO_SHOW:
break
dayStart = time.parse_time(day[0]["startTime"])
temps = [p["temperature"] for p in day]
temps = [to_celsius(p["temperature"], celsius) for p in day]
high = int(math.round(max(temps)))
forecast = mode([p["shortForecast"] for p in day])

Expand Down Expand Up @@ -151,9 +152,22 @@ def get_schema():
desc = "Location for which to display weather data.",
icon = "locationDot",
),
schema.Toggle(
id = "celsius",
name = "Celsius",
desc = "Enable to show temperature in Celsius",
icon = "temperatureHalf",
default = False,
),
],
)

def to_celsius(val, is_celsius):
if is_celsius:
return int(math.round((val - 32) * 5 / 9))
else:
return val

# Weather icons from https://www.flaticon.com/free-icons/weather
# (free with attribution)
SUNNY = base64.decode("""
Expand Down