Skip to content

Commit ba61b4d

Browse files
adding LAX Departures app (#3016)
* change typecode lookup backend * adding lax departures app
1 parent ff63551 commit ba61b4d

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
load("encoding/json.star", "json")
2+
load("http.star", "http")
3+
load("render.star", "render")
4+
5+
# Fetch data from your deployed Lambda API
6+
def fetch_data():
7+
res = http.get("https://up8y1e1xae.execute-api.us-east-1.amazonaws.com/lax-departures")
8+
if res.status_code != 200:
9+
return None
10+
11+
data = json.decode(res.body())
12+
if type(data.get("departures", None)) != "list":
13+
return None
14+
15+
return data["departures"][:6] # First 6 flights max
16+
17+
# Build one page of output
18+
def make_page(flights, page_index, total_pages):
19+
rows = []
20+
21+
# Header row with left and right components
22+
rows.append(render.Row(children = [
23+
render.Text("Next From LAX", font = "tb-8", color = "#fcf7c5"),
24+
render.Text(" {}/{}".format(page_index + 1, total_pages), font = "5x8", color = "#666666"),
25+
]))
26+
27+
# Add flight rows
28+
for flight in flights:
29+
status = flight.get("status", "").lower()
30+
31+
if "canceled" in status:
32+
time_color = "#ff5555" # red
33+
elif flight.get("is_past"):
34+
time_color = "#888888" # gray
35+
else:
36+
time_color = "#a8ffb0" # light green
37+
38+
rows.append(
39+
render.Row(children = [
40+
render.Text(flight["scheduled_time"], font = "5x8", color = time_color),
41+
render.Text(" {} {}".format(flight["airline"], flight["destination"]), font = "5x8"),
42+
]),
43+
)
44+
45+
return render.Column(children = rows)
46+
47+
# Main entrypoint
48+
def main():
49+
flights = fetch_data()
50+
if flights == None:
51+
return render.Root(child = render.Text("Error", font = "5x8", color = "#ff0000"))
52+
53+
pages = []
54+
total_pages = (min(len(flights), 6) + 2) // 3 # ceil(len / 3)
55+
56+
for page_index, i in enumerate(range(0, min(len(flights), 6), 3)):
57+
page_flights = flights[i:i + 3]
58+
page = make_page(page_flights, page_index, total_pages)
59+
60+
# Repeat page N times to control timing
61+
for _ in range(200):
62+
pages.append(page)
63+
64+
return render.Root(
65+
child = render.Sequence(children = pages),
66+
)

apps/lax_departures/manifest.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
id: lax-departures
3+
name: LAX Departures
4+
summary: LAX Departing Flights
5+
desc: Shows the next six flights departing from LAX, with their scheduled departure time, carrier, and destination.
6+
author: Conor McLaughlin

0 commit comments

Comments
 (0)