forked from tidbyt/pixlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sunrise.star
65 lines (59 loc) · 2.04 KB
/
sunrise.star
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
load("render.star", "render")
load("schema.star", "schema")
load("time.star", "time")
load("encoding/json.star", "json")
load("sunrise.star", "sunrise")
DEFAULT_LOCATION = """
{
"lat": "40.6781784",
"lng": "-73.9441579",
"description": "Brooklyn, NY, USA",
"locality": "Brooklyn",
"place_id": "ChIJCSF8lBZEwokRhngABHRcdoI",
"timezone": "America/New_York"
}
"""
def main(config):
location = config.get("location", DEFAULT_LOCATION)
loc = json.decode(location)
lat, lng = float(loc["lat"]), float(loc["lng"])
now = time.now()
rise = sunrise.sunrise(lat, lng, now)
set = sunrise.sunset(lat, lng, now)
# Check if the sun does not rise or set today. This would happen if the
# location of the deivce is close to the north or south pole where there are
# many days of light or darkness. Maybe someone brought their Tidbyt to the
# Amundsen-Scott South Pole Station! How cool would that be?
if rise == None or set == None:
return render.Root(
child = render.Column(
children = [
render.Text("Now: %s" % now.in_location(loc["timezone"]).format("3:04 PM")),
render.Marquee(
width = 64,
child = render.Text("Sun doesn't rise or set today."),
),
],
),
)
return render.Root(
child = render.Column(
children = [
render.Text("Now: %s" % now.in_location(loc["timezone"]).format("3:04 PM")),
render.Text("Rise: %s" % rise.in_location(loc["timezone"]).format("3:04 PM")),
render.Text("Set: %s" % set.in_location(loc["timezone"]).format("3:04 PM")),
],
),
)
def get_schema():
return schema.Schema(
version = "1",
fields = [
schema.Location(
id = "location",
name = "Location",
desc = "Location for which to display time.",
icon = "locationDot",
),
],
)