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

[MinorVersion] Update config sample, add additional logic to like twe… #4

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions config.SAMPLE.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"follow_poster": true,
"user_blacklist": [ "", ""],
"word_blacklist": ["RT", "♺"],
"day_to_tweet": 1
"day_to_tweet": 1,
"favourite_tweets": false
},
{
"search_query": "#test2",
Expand All @@ -21,6 +22,7 @@
"follow_poster": false,
"user_blacklist": [ "", ""],
"word_blacklist": ["RT", "♺"],
"day_to_tweet": 1
"day_to_tweet": 1,
"favourite_tweets": false
}]
}
31 changes: 19 additions & 12 deletions retweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@
import tweepy


def can_tweet(day_to_tweet):
"""Checks the current day against the day tweets should be retweeted"""
def filtered_tweet_check(tweet):
"""Filters out retweets and @ mentions to avoid spam"""

if day_to_tweet == 7:
if not tweet.retweeted and '@' not in tweet.text:
return True

if datetime.datetime.today().weekday() == day_to_tweet:
return False


def can_tweet_today(day_to_tweet):
"""Checks the current day against the day tweets should be retweeted"""

if datetime.datetime.today().weekday() == day_to_tweet or day_to_tweet == 7:
return True

return False


def get_hashtag_file_id(hashtag):
"""Gets the file id of the passed hashtag"""

Expand Down Expand Up @@ -50,12 +57,12 @@ def retweet_logic(api, query_objects):
"""Performs the logic surrounding retweeting the query objects defined in the config file"""

for query_object in query_objects:
if can_tweet(query_object['day_to_tweet']) is False:
if can_tweet_today(query_object['day_to_tweet']) is False:
continue

savepoint = get_hashtag_savepoint(query_object['search_query'])
timeline_iterator = tweepy.Cursor(api.search, q=query_object['search_query'], since_id=savepoint,
lang=query_object['tweet_language']).items(query_object['tweet_limit'])
lang=query_object['tweet_language'], ).items(query_object['tweet_limit'])

timeline = []
for status in timeline_iterator:
Expand All @@ -66,10 +73,6 @@ def retweet_logic(api, query_objects):
except IndexError:
last_tweet_id = savepoint

# FIX ME
# uncomment to remove all tweets with an @mention
# timeline = filter(lambda status: status.text[0] = "@", timeline)

timeline = filter(lambda status: not any(word in status.text.split()
for word in query_object['word_blacklist']), timeline)
timeline = filter(
Expand All @@ -88,8 +91,12 @@ def retweet_logic(api, query_objects):
"name": status.author.screen_name.encode('utf-8'),
"message": status.text.encode('utf-8')})

API.retweet(status.id)
tweet_count += 1
if filtered_tweet_check(status) is True:
API.retweet(status.id)
tweet_count += 1

if query_object['favourite_tweets'] is True:
API.create_favorite(status.id)

if query_object['follow_poster'] is True:
API.create_friendship(status.author.id)
Expand Down