Skip to content

Commit 25786de

Browse files
authored
Merge pull request #942 from pimoroni/patch-inky-launcher
Patch inky launcher
2 parents 9d7d651 + a387e45 commit 25786de

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

micropython/examples/inky_frame/inkylauncher/news_headlines.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,24 @@
1717
code = qrcode.QRCode()
1818

1919

20-
def read_until(stream, char):
20+
def read_until(stream, find):
2121
result = b""
22-
while True:
23-
c = stream.read(1)
24-
if c == char:
22+
while len(c := stream.read(1)) > 0:
23+
if c == find:
2524
return result
2625
result += c
2726

2827

29-
def discard_until(stream, c):
30-
while stream.read(1) != c:
31-
pass
28+
def discard_until(stream, find):
29+
_ = read_until(stream, find)
3230

3331

3432
def parse_xml_stream(s, accept_tags, group_by, max_items=3):
3533
tag = []
3634
text = b""
3735
count = 0
3836
current = {}
37+
3938
while True:
4039
char = s.read(1)
4140
if len(char) == 0:
@@ -79,9 +78,9 @@ def parse_xml_stream(s, accept_tags, group_by, max_items=3):
7978

8079
else:
8180
current_tag = read_until(s, b">")
82-
tag += [next_char + current_tag.split(b" ")[0]]
83-
text = b""
84-
gc.collect()
81+
if not current_tag.endswith(b"/"):
82+
tag += [next_char + current_tag.split(b" ")[0]]
83+
text = b""
8584

8685
else:
8786
text += char
@@ -113,7 +112,7 @@ def get_rss():
113112

114113
except OSError as e:
115114
print(e)
116-
return False
115+
return []
117116

118117

119118
feed = None
@@ -135,7 +134,7 @@ def draw():
135134
graphics.set_pen(0)
136135

137136
# Draws 2 articles from the feed if they're available.
138-
if feed:
137+
if len(feed) > 0:
139138

140139
# Title
141140
graphics.set_pen(graphics.create_pen(200, 0, 0))

0 commit comments

Comments
 (0)