Skip to content

Commit 027f158

Browse files
Fix repeated tweet printing
1 parent 3b4dc2a commit 027f158

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

twitter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def issueRequestAndDecodeResponse(method, url, body, headers):
6262
connection.request(method, url, body, headers)
6363
response = connection.getresponse()
6464
if response.status != 200:
65-
# This is OK for command-line testing, otherwise
65+
# This is OK for command-line testing, otherwise
6666
# keep it commented out when using main.py
6767
# print('HTTP error: %d' % response.status)
6868
exit(-1)
@@ -101,6 +101,8 @@ def issueRequestAndDecodeResponse(method, url, body, headers):
101101

102102
# Display results. ---------------------------------------------------------
103103

104+
maxId = data['search_metadata']['max_id_str']
105+
104106
for tweet in data['statuses']:
105107

106108
printer.inverseOn()
@@ -111,11 +113,15 @@ def issueRequestAndDecodeResponse(method, url, body, headers):
111113
printer.print('{:<32}'.format(tweet['created_at']))
112114
printer.underlineOff()
113115

116+
# max_id_str is not always present, so check tweet IDs as fallback
117+
id = tweet['id_str']
118+
if(id > maxId): maxId = id # String compare is OK for this
119+
114120
# Remove HTML escape sequences
115121
# and remap Unicode values to nearest ASCII equivalents
116122
printer.print(unidecode(
117123
HTMLParser.HTMLParser().unescape(tweet['text'])))
118124

119125
printer.feed(3)
120126

121-
print(data['search_metadata']['max_id_str']) # Piped back to calling process
127+
print(maxId) # Piped back to calling process

0 commit comments

Comments
 (0)