From f0ecd2347d517e372b22b34b3001d865e5b62d8e Mon Sep 17 00:00:00 2001 From: Harmon Date: Tue, 29 Dec 2020 03:22:36 -0600 Subject: [PATCH] Simplify StreamListener.on_data --- tweepy/streaming.py | 47 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index b7e7d5f..1821727 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -48,36 +48,27 @@ class StreamListener: if 'in_reply_to_status_id' in data: status = Status.parse(self.api, data) - if self.on_status(status) is False: - return False - elif 'delete' in data: + return self.on_status(status) + if 'delete' in data: delete = data['delete']['status'] - if self.on_delete(delete['id'], delete['user_id']) is False: - return False - elif 'event' in data: + return self.on_delete(delete['id'], delete['user_id']) + if 'event' in data: status = Status.parse(self.api, data) - if self.on_event(status) is False: - return False - elif 'limit' in data: - if self.on_limit(data['limit']['track']) is False: - return False - elif 'disconnect' in data: - if self.on_disconnect(data['disconnect']) is False: - return False - elif 'warning' in data: - if self.on_warning(data['warning']) is False: - return False - elif 'scrub_geo' in data: - if self.on_scrub_geo(data['scrub_geo']) is False: - return False - elif 'status_withheld' in data: - if self.on_status_withheld(data['status_withheld']) is False: - return False - elif 'user_withheld' in data: - if self.on_user_withheld(data['user_withheld']) is False: - return False - else: - log.error("Unknown message type: %s", raw_data) + return self.on_event(status) + if 'limit' in data: + return self.on_limit(data['limit']['track']) + if 'disconnect' in data: + return self.on_disconnect(data['disconnect']) + if 'warning' in data: + return self.on_warning(data['warning']) + if 'scrub_geo' in data: + return self.on_scrub_geo(data['scrub_geo']) + if 'status_withheld' in data: + return self.on_status_withheld(data['status_withheld']) + if 'user_withheld' in data: + return self.on_user_withheld(data['user_withheld']) + + log.error("Unknown message type: %s", raw_data) def keep_alive(self): """Called when a keep-alive arrived""" -- 2.25.1