Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Added POTUS twitter account and filters for messages with '-DJT' #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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"
Expand Down Expand Up @@ -58,7 +59,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():
Expand Down Expand Up @@ -260,12 +261,16 @@ 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.
if user_id_str != TRUMP_USER_ID:
# We're only interested in tweets from Mr. Trump himself
# or from the POTUS account so skip the rest.
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
# 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)

Expand Down