Skip to content

Commit cf86085

Browse files
committed
Handle bytes more directly
Since we're using a Protobuf API, pull the HTTP body as bytes rather than a string. This works around weird behavior in ord. Depends on tidbyt/pixlet#1095.
1 parent 79c8301 commit cf86085

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

nyc_subway_zoom.star

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GTFS_FEED_URL = "https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fg
66

77
# The ID of the stop to watch.
88
# For the NYC MTA, see: http://web.mta.info/developers/data/nyct/subway/google_transit.zip
9-
STOP_ID = "123S"
9+
STOP_ID = b"123S"
1010

1111
# The color of the bullet to use for arrivals.
1212
BULLET_COLOR = "#ee352e"
@@ -57,7 +57,7 @@ def render_bullet(route):
5757
return render.Circle(
5858
color = BULLET_COLOR,
5959
diameter = 7,
60-
child = render.Text(route, font = "tom-thumb"),
60+
child = render.Text(str(route), font = "tom-thumb"),
6161
)
6262

6363
def render_eta(eta):
@@ -89,7 +89,7 @@ STOP_TIME_UPDATE_ARRIVAL_FIELD_NUMBER = 2
8989
STOP_TIME_EVENT_ARRIVAL_TIME_FIELD_NUMBER = 2
9090

9191
def gtfs_get_feed(url):
92-
return http.get(url, ttl_seconds = 5).body()
92+
return http.get(url, ttl_seconds = 5).bytes()
9393

9494
def gtfs_get_upcoming_arrivals(stop_id, reader):
9595
upcoming_arrivals = []
@@ -113,7 +113,6 @@ def gtfs_get_upcoming_arrivals(stop_id, reader):
113113
arrival_time = time.from_timestamp(arrival_times[0])
114114
if arrival_time > time.now():
115115
upcoming_arrivals.append(struct(route_id = route_id, eta = arrival_time))
116-
117116
return sorted(upcoming_arrivals, key = lambda x: x.eta)
118117

119118
# ==> Generic Protobuf decoding.
@@ -178,6 +177,6 @@ def proto_decode_len(reader):
178177
return out, reader
179178

180179
def proto_next_byte(reader):
181-
out = reader.elem_ords()[0]
180+
out = ord(reader[0])
182181
reader = reader[1:]
183182
return out, reader

0 commit comments

Comments
 (0)