Skip to content

Commit

Permalink
Twitter_bot: Add user account to blacklist
Browse files Browse the repository at this point in the history
- This commit fixes #57
  • Loading branch information
ananthanandanan authored and Aniketh01 committed May 16, 2020
1 parent 55e4b83 commit 9e1fc89
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions twitter_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def nawab_store_id(self, tweet_id):

def isUserwhitelisted(self, userName):
### Search if the Whitelist user is in file
if not any(acc["Whitelist"] == userName.lower() for index, acc in self.data.iterrows()):
if any(acc["Whitelist"] == userName.lower() for index, acc in self.data.iterrows()):
return True
return False

def isUserBanned(self, userName):
### Search if the Blacklisted user is in file
if not any(acc["Blacklist"] == userName.lower() for index, acc in self.data.iterrows()):
def isUserBanned(self, userName, admin_user):
### Search if the Blacklisted user is in file,and blacklist the bot's account
if not any((acc["Blacklist"] == userName.lower()) or (admin_user==userName.lower()) for index, acc in self.data.iterrows()):
return True
return False

Expand All @@ -78,7 +78,7 @@ def nawab_check_tweet(self, tweet_id):
return True
else:
return False

def nawab_curate_list(self, api):
query = self.nawab_read_list()
self.nawab_search(api, query)
Expand All @@ -103,6 +103,9 @@ def nawab_search(self, api, query):
user = tweets.user.screen_name
id = tweets.id
text = tweets.full_text
## obtain user account for blacklist
admin = api.me()
admin_user = admin.screen_name

if (self.nawab_check_tweet(id)) and ('RT @' in text):
if self.level == logging.WARNING:
Expand All @@ -112,7 +115,7 @@ def nawab_search(self, api, query):
self.nw_logger.logger(
'\t|' + str(id) + 'already exists in the database or it is a retweet', 'error', 'Error')
else:
if (self.isUserwhitelisted(user) or (self.isUserBanned(user) and self.isSafeKeyword(text))):
if (self.isUserwhitelisted(user) or (self.isUserBanned(user,admin_user) and self.isSafeKeyword(text))):
if not (self.nawab_check_tweet(id)):
self.nawab_store_id(id)
url = 'https://twitter.com/' + \
Expand Down Expand Up @@ -158,7 +161,6 @@ def nawab_retweet_tweet(self, api):
fp.write('INFO:' + time.strftime("%m/%d/%Y %I:%M:%S %p ") + "\t|Nawab retweeted " +
str(tweet_id) + " successfully \n")


self.nw_logger.logger('\t|Nawab retweeted' +
str(tweet_id) + 'successfully', 'info', 'Results')

Expand Down

0 comments on commit 9e1fc89

Please sign in to comment.