From b359bddd34c22670f817ebbe19f6213e7dd46a69 Mon Sep 17 00:00:00 2001 From: David Kyo Date: Fri, 10 Feb 2017 16:00:44 -0800 Subject: [PATCH 1/3] Added POTUS twitter account and filters for messages with '-DJT' --- twitter.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/twitter.py b/twitter.py index 1b45cc5..4e0449d 100644 --- a/twitter.py +++ b/twitter.py @@ -24,6 +24,7 @@ # The user ID of @realDonaldTrump. TRUMP_USER_ID = "25073877" +POTUS_USER_ID = "822215679726100480" # The URL pattern for links to tweets. TWEET_URL = "https://twitter.com/%s/status/%s" @@ -57,7 +58,7 @@ def start_streaming(self, callback): twitter_stream = Stream(self.twitter_auth, self.twitter_listener) self.logs.debug("Starting stream.") - twitter_stream.filter(follow=[TRUMP_USER_ID]) + twitter_stream.filter(follow=[TRUMP_USER_ID,POTUS_USER_ID]) # If we got here because of an API error, raise it. if self.twitter_listener.get_error_status(): @@ -244,6 +245,15 @@ def handle_data(self, logs, data): logs.debug("Skipping tweet from user: %s (%s)" % (screen_name, user_id_str)) return + # Only look at POTUS tweets from POTUS, then check that tweet is signed -DJT + if user_id_str != POTUS_USER_ID: + logs.debug("Skipping tweet from user: %s (%s)" % + (screen_name, user_id_str)) + return + elif '-DJT' not in tweet: + logs.debug("Tweet not signed -DJT: %s" % + (tweet)) + return logs.info("Examining tweet: %s" % tweet) From 2e490d32cf5e6ed0f0a778f932fcd686fdf9e8f2 Mon Sep 17 00:00:00 2001 From: David Kyo Date: Fri, 10 Feb 2017 17:32:57 -0800 Subject: [PATCH 2/3] Skip if user isn't Trump or POTUS. Then check that POTUS tweets are signed -DJT --- twitter.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/twitter.py b/twitter.py index 4e0449d..a65e1b4 100644 --- a/twitter.py +++ b/twitter.py @@ -237,22 +237,17 @@ def handle_data(self, logs, data): logs.error("Malformed tweet: %s" % tweet) return - # We're only interested in tweets from Mr. Trump himself, so skip the - # rest. + # We're only interested in tweets from Mr. Trump himself + # or from the POTUS account so skip the rest. user_id_str = tweet["user"]["id_str"] screen_name = tweet["user"]["screen_name"] - if user_id_str != TRUMP_USER_ID: + if user_id_str != TRUMP_USER_ID or user_id_str != POTUS_USER_ID: logs.debug("Skipping tweet from user: %s (%s)" % (screen_name, user_id_str)) return - # Only look at POTUS tweets from POTUS, then check that tweet is signed -DJT - if user_id_str != POTUS_USER_ID: - logs.debug("Skipping tweet from user: %s (%s)" % - (screen_name, user_id_str)) - return - elif '-DJT' not in tweet: - logs.debug("Tweet not signed -DJT: %s" % - (tweet)) + # Also skip if tweet is from POTUS but not signed -DJT + if user_id_str == POTUS_USER_ID and '-DJT' not in tweet: + logs.debug("Skipping POTUS tweet because not signed -DJT") return logs.info("Examining tweet: %s" % tweet) From 149d233259b8f88624dc8e8db4e7dbb853f5e39d Mon Sep 17 00:00:00 2001 From: David Kyo Date: Fri, 10 Feb 2017 17:38:19 -0800 Subject: [PATCH 3/3] or -> and --- twitter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter.py b/twitter.py index a65e1b4..50d960a 100644 --- a/twitter.py +++ b/twitter.py @@ -241,7 +241,7 @@ def handle_data(self, logs, data): # or from the POTUS account so skip the rest. user_id_str = tweet["user"]["id_str"] screen_name = tweet["user"]["screen_name"] - if user_id_str != TRUMP_USER_ID or user_id_str != POTUS_USER_ID: + if user_id_str != TRUMP_USER_ID and user_id_str != POTUS_USER_ID: logs.debug("Skipping tweet from user: %s (%s)" % (screen_name, user_id_str)) return