Adding VERBOSE variable if you want to remove a lot of print
This commit is contained in:
parent
79caf5b097
commit
cfdc491ec8
2 changed files with 17 additions and 6 deletions
|
@ -18,6 +18,7 @@ TOKEN_SECRET | Token d'accès secret disponible dans la section `Authenticati
|
||||||
CONSUMER_KEY | Clé API disponible dans la section `Consumer Keys`
|
CONSUMER_KEY | Clé API disponible dans la section `Consumer Keys`
|
||||||
CONSUMER_SECRET | Clé secrète API disponible dans la section `Consumer Keys`
|
CONSUMER_SECRET | Clé secrète API disponible dans la section `Consumer Keys`
|
||||||
PSEUDOS | Pseudos du ou des compte.s que vous voulez écouter pour le snipe (a séparer avec une virgule **sans** espaces)
|
PSEUDOS | Pseudos du ou des compte.s que vous voulez écouter pour le snipe (a séparer avec une virgule **sans** espaces)
|
||||||
|
VERBOSE | Affiche plus de messages dans la console [False\|True] (facultatif, par défaut sur False)
|
||||||
|
|
||||||
Ensuite installe les dépendances avec `pip install -r requirements.txt`.
|
Ensuite installe les dépendances avec `pip install -r requirements.txt`.
|
||||||
|
|
||||||
|
|
12
main.py
12
main.py
|
@ -13,6 +13,12 @@ def load(variables) -> dict:
|
||||||
load_dotenv() # load .env file
|
load_dotenv() # load .env file
|
||||||
for var in variables:
|
for var in variables:
|
||||||
try:
|
try:
|
||||||
|
if var == "VERBOSE":
|
||||||
|
try:
|
||||||
|
res = bool(environ[var])
|
||||||
|
except:
|
||||||
|
res = False
|
||||||
|
else:
|
||||||
res = environ[var]
|
res = environ[var]
|
||||||
if var == "PSEUDOS":
|
if var == "PSEUDOS":
|
||||||
res = list(set(res.split(',')) - {""}) # create a list for the channels and remove blank channels and doubles
|
res = list(set(res.split(',')) - {""}) # create a list for the channels and remove blank channels and doubles
|
||||||
|
@ -42,6 +48,7 @@ class Listener(StreamListener):
|
||||||
regex = r"https?:\/\/\S+| +?\?|\?| +?\!| ?\!|-|~|(?<=ui)i+|@\S+|\.+|(?<=na)a+(?<!n)|(?<=quoi)i+|(?<=no)o+(?<!n)|…"
|
regex = r"https?:\/\/\S+| +?\?|\?| +?\!| ?\!|-|~|(?<=ui)i+|@\S+|\.+|(?<=na)a+(?<!n)|(?<=quoi)i+|(?<=no)o+(?<!n)|…"
|
||||||
tweetText = sub(regex, "", tweet.lower())
|
tweetText = sub(regex, "", tweet.lower())
|
||||||
lastWord = tweetText.split()[-1:][0]
|
lastWord = tweetText.split()[-1:][0]
|
||||||
|
if keys["VERBOSE"]:
|
||||||
print(f"Tweet trouvé de {status._json['user']['screen_name']} (dernier mot : \"{lastWord}\")...", end = " ")
|
print(f"Tweet trouvé de {status._json['user']['screen_name']} (dernier mot : \"{lastWord}\")...", end = " ")
|
||||||
if lastWord in universalBase: # check if the last word found is a supported word
|
if lastWord in universalBase: # check if the last word found is a supported word
|
||||||
answer = None
|
answer = None
|
||||||
|
@ -49,8 +56,10 @@ class Listener(StreamListener):
|
||||||
if lastWord in mot[1]:
|
if lastWord in mot[1]:
|
||||||
answer = answers[mot[0]]
|
answer = answers[mot[0]]
|
||||||
if answer == None:
|
if answer == None:
|
||||||
|
if keys["VERBOSE"]:
|
||||||
print(f"{errorMessage} Aucune réponse trouvée.")
|
print(f"{errorMessage} Aucune réponse trouvée.")
|
||||||
else:
|
else:
|
||||||
|
if keys["VERBOSE"]:
|
||||||
print(f"Envoie d'un {answer[0]}...", end = " ")
|
print(f"Envoie d'un {answer[0]}...", end = " ")
|
||||||
try: # send answer
|
try: # send answer
|
||||||
self.api.update_status(status = choice(answer), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
self.api.update_status(status = choice(answer), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
||||||
|
@ -58,6 +67,7 @@ class Listener(StreamListener):
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(f"\n{errorMessage} {error}")
|
print(f"\n{errorMessage} {error}")
|
||||||
else:
|
else:
|
||||||
|
if keys["VERBOSE"]:
|
||||||
print("Annulation car le dernier mot n'est pas intéressant.")
|
print("Annulation car le dernier mot n'est pas intéressant.")
|
||||||
|
|
||||||
def do_stuff(self):
|
def do_stuff(self):
|
||||||
|
@ -162,5 +172,5 @@ if __name__ == '__main__':
|
||||||
triggerWords = permute(universalBase)
|
triggerWords = permute(universalBase)
|
||||||
|
|
||||||
# loading environment variables and launching the bot
|
# loading environment variables and launching the bot
|
||||||
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDOS"])
|
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDOS", "VERBOSE"])
|
||||||
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDOS"])
|
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDOS"])
|
||||||
|
|
Reference in a new issue