Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ignore_threads option to leave threads out of the bowl #49

Merged
merged 1 commit into from Jul 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion rainbowmindmachine/SocialSheep.py
Expand Up @@ -85,6 +85,10 @@ def flush(self, **kwargs):
Currently only one parameter:

search_terms String to search for

ignore_threads Whether to :ignore: tweets that occur somewhere
inside (potentially long) threads

"""
if 'search_terms' in kwargs:
search_terms = kwargs['search_terms']
Expand All @@ -93,13 +97,35 @@ def flush(self, **kwargs):
err += "Specify search_terms kwarg: flush(search_terms = '...')"
raise Exception(err)

if 'ignore_threads' in kwargs:
ignore_threads = kwargs['ignore_threads']
else:
# be safe
ignore_threads = True


self.bowl = []
for search_term in search_terms:
self.bowl += list(self.api.GetSearch(term=search_term,count=self.capacity))

if ignore_threads:

# filter tweets that have an "in_reply_to_status_id" field
for tweet in self.api.GetSearch( term=search_term,
count=self.capacity):

if tweet.in_reply_to_status_id is None:
self.bowl.append(tweet)

else:

# grab every tweet
self.bowl += list(self.api.GetSearch(term=search_term,count=self.capacity))

# self.bowl is a list of Status objects
# this is really useful:
# http://python-twitter.readthedocs.io/en/latest/_modules/twitter/models.html#Status
# so is this:
# https://github.com/bear/python-twitter/blob/e17af0e67b7270ae448908ad44235d03562509eb/twitter/models.py
#
# a BurdHurd is just a list of usernames
# pulled straight out of the toilet.
Expand Down