Skip to content

Commit

Permalink
Merge pull request #14 from Otavio-S/develop
Browse files Browse the repository at this point in the history
filters tunning and translation correction
  • Loading branch information
otaviouss authored Feb 13, 2022
2 parents 8fecfd7 + f4d6f84 commit a13c7d3
Showing 1 changed file with 80 additions and 55 deletions.
135 changes: 80 additions & 55 deletions ethicsBot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from asyncio.log import logger
from deep_translator import GoogleTranslator
from platform import python_version
from dotenv import load_dotenv
Expand Down Expand Up @@ -36,14 +37,13 @@ def __init__(self, consumer_key, consumer_secret, access_token,
self.stats_json = dict()

def on_status(self, status):
'''
Tweet the result of the analysis executed by pegabot
Parameters:
status (string):
Returns:
total (int): Result (total analysis)
'''

st = status
try:
status = self.api.get_status(status.id_str, tweet_mode="extended")
except:
return

## Filters ##

# If it is a retweet
Expand All @@ -66,65 +66,90 @@ def on_status(self, status):

# Non Desired Terms
if(
status.text.find("deal") != -1 or
status.text.find("promotion") != -1 or
status.text.find("download") != -1 or
status.text.find("sale") != -1 or
status.text == self.last_tweet
status.full_text.find("deal") != -1 or
status.full_text.find("Deal") != -1 or
status.full_text.find("promotion") != -1 or
status.full_text.find("Promotion") != -1 or
status.full_text.find("download") != -1 or
status.full_text.find("Download") != -1 or
status.full_text.find("sale") != -1 or
status.full_text.find("Sale") != -1 or
status.full_text == self.last_tweet
):
return

# Related Terms
if (
status.text.find("software") != -1 or
status.text.find(" tech ") != -1 or
status.text.find(" tech.") != -1 or
status.text.find("internet") != -1 or
status.text.find("Internet") != -1 or
status.text.find("computing") != -1 or
status.text.find("Computing") != -1 or
status.text.find("hacker") != -1 or
status.text.find("hacking") != -1 or
status.text.find("data") != -1 or status.text.find("dados") != -1 or
status.text.find("Data") != -1 or status.text.find("Dados") != -1 or
status.text.find("coding") != -1 or status.text.find("codificar") != -1 or
status.text.find("programming") != -1 or status.text.find("programação") != -1 or
status.text.find(" IT ") != -1 or status.text.find(" TI ") != -1 or
status.text.find("computation") != -1 or status.text.find("computação") != -1 or
status.text.find("Computation") != -1 or status.text.find("Computação") != -1 or
status.text.find("social media") != -1 or status.text.find("redes sociais") != -1 or
status.text.find("Social media") != -1 or status.text.find("Redes sociais") != -1 or
status.text.find("algorithm") != -1 or status.text.find("algoritmo") != -1 or
status.text.find("Algorithm") != -1 or status.text.find("Algoritmo") != -1 or
status.text.find("technology") != -1 or status.text.find("tecnologia") != -1 or
status.text.find("Technology") != -1 or status.text.find("Tecnologia") != -1 or
status.text.find("cloud") != -1 or status.text.find("nuvem") != -1 or
status.text.find(" AI ") != -1 or status.text.find(" IA ") != -1 or
status.text.find(" AI.") != -1 or status.text.find(" IA.") != -1 or
status.text.find("artificial inteligence") != -1 or status.text.find("inteligência artificial") != -1 or
status.text.find("Artificial Inteligence") != -1 or status.text.find("Inteligência Artificial") != -1 or
status.text.find("requirements engineering") != -1 or status.text.find("engenharia de requisitos") != -1
status.full_text.find("software") != -1 or
status.full_text.find(" tech ") != -1 or
status.full_text.find(" tech.") != -1 or
status.full_text.find("internet") != -1 or
status.full_text.find("Internet") != -1 or
status.full_text.find("computing") != -1 or
status.full_text.find("Computing") != -1 or
status.full_text.find("hacker") != -1 or
status.full_text.find("hacking") != -1 or
status.full_text.find("data") != -1 or status.full_text.find("dados") != -1 or
status.full_text.find("Data") != -1 or status.full_text.find("Dados") != -1 or
status.full_text.find("coding") != -1 or status.full_text.find("codificar") != -1 or
status.full_text.find("programming") != -1 or status.full_text.find("programação") != -1 or
status.full_text.find(" IT ") != -1 or status.full_text.find(" TI ") != -1 or
status.full_text.find("computation") != -1 or status.full_text.find("computação") != -1 or
status.full_text.find("Computation") != -1 or status.full_text.find("Computação") != -1 or
status.full_text.find("social media") != -1 or status.full_text.find("redes sociais") != -1 or
status.full_text.find("Social media") != -1 or status.full_text.find("Redes sociais") != -1 or
status.full_text.find("algorithm") != -1 or status.full_text.find("algoritmo") != -1 or
status.full_text.find("Algorithm") != -1 or status.full_text.find("Algoritmo") != -1 or
status.full_text.find("technology") != -1 or status.full_text.find("tecnologia") != -1 or
status.full_text.find("Technology") != -1 or status.full_text.find("Tecnologia") != -1 or
status.full_text.find("cloud") != -1 or status.full_text.find("nuvem") != -1 or
status.full_text.find(" AI ") != -1 or status.full_text.find(" IA ") != -1 or
status.full_text.find(" AI.") != -1 or status.full_text.find(" IA.") != -1 or
status.full_text.find("artificial inteligence") != -1 or status.full_text.find("inteligência artificial") != -1 or
status.full_text.find("Artificial Inteligence") != -1 or status.full_text.find("Inteligência Artificial") != -1 or
status.full_text.find("requirements engineering") != -1 or status.full_text.find("engenharia de requisitos") != -1
):
pass
else:
return

# print('---\nUsername: ' + status.user.screen_name)
# print(status.text)
print('---\nUsername: ' + status.user.screen_name)
print(status.full_text)

translated_tweet = GoogleTranslator(source='auto', target='pt').translate(status.text)
translated_tweet = GoogleTranslator(source='auto', target='pt').translate(status.full_text)

# Updating last retweeted tweet
self.last_tweet = status.text

if not status.retweeted:
# Retweet, since we have not retweeted it yet
try:
# self.api.retweet(status.id)
self.api.update_status(translated_tweet, attachment_url='https://twitter.com/'+status.user.screen_name+'/status/'+status.id_str)
except Exception as e:
# logger.error("Error on fav and retweet", exc_info=True)
return
translated_tweet = translated_tweet.replace("&", "&")

if(translated_tweet == status.full_text):
# Updating last retweeted tweet
self.last_tweet = status.full_text

if not status.retweeted:
# Retweet, since we have not retweeted it yet
try:
self.api.retweet(status.id_str)
# self.api.update_status(translated_tweet, attachment_url='https://twitter.com/'+status.user.screen_name+'/status/'+status.id_str)
except Exception as e:
# logger.error("Error on fav and retweet", exc_info=True)
return

else:
# Updating last retweeted tweet
self.last_tweet = translated_tweet

if not status.retweeted:
# Retweet, since we have not retweeted it yet
try:
# self.api.retweet(status.id)
self.api.update_status(translated_tweet, attachment_url='https://twitter.com/'+status.user.screen_name+'/status/'+status.id_str)
except Exception as e:
try:
translated_tweet = GoogleTranslator(source='auto', target='pt').translate(st.text)
translated_tweet = translated_tweet.replace("&", "&")
self.api.update_status(translated_tweet, attachment_url='https://twitter.com/'+st.user.screen_name+'/status/'+st.id_str)
except:
self.api.retweet(status.id_str)
# logger.error("Error on fav and retweet", exc_info=True)

def on_limit(self,status):
# Rate Limit Exceeded, Sleep for 15 Mins
Expand Down Expand Up @@ -161,4 +186,4 @@ def listen(string_list = [""]):


if __name__ == "__main__":
listen(string_list = ["ethics", "ethical", "ethically", "ética", "ético", "social computing", "computação social", "#ethicsBot", "#botEtico"])
listen(string_list = ["ethics", "ethical", "ethically", "ética", "ético", "#ethicsBot", "#botEtico"])

0 comments on commit a13c7d3

Please sign in to comment.