-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathexample.star
69 lines (63 loc) · 1.74 KB
/
example.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
66
67
68
69
load("encoding/json.star", "json")
load("render.star", "render")
load("schema.star", "schema")
EXAMPLE_LOCATION = """
{
"lat": "40.6781784",
"lng": "-73.9441579",
"description": "Brooklyn, NY, USA",
"locality": "Brooklyn",
"place_id": "ChIJCSF8lBZEwokRhngABHRcdoI",
"timezone": "America/New_York"
}
"""
def main(config):
option = config.get("station", '{"display": "Back Bay", "value": "back_bay"}')
station = json.decode(option)
return render.Root(
child = render.Marquee(
width = 64,
child = render.Text(station["display"]),
),
)
def get_stations(location):
loc = json.decode(location) # See example location above.
locality = loc["locality"]
if locality == "New York":
return [
schema.Option(
display = "Grand Central",
value = "grand_central",
),
schema.Option(
display = "34th Street Penn Station",
value = "34th_street_penn_station",
),
]
elif locality == "Philadelphia":
return [
schema.Option(
display = "30th Street Station",
value = "30th_street_station",
),
]
else:
return [
schema.Option(
display = "Back Bay",
value = "back_bay",
),
]
def get_schema():
return schema.Schema(
version = "1",
fields = [
schema.LocationBased(
id = "station",
name = "Train Station",
desc = "A list of train stations based on a location.",
icon = "train",
handler = get_stations,
),
],
)