Compare commits
No commits in common. "f595dcd83d457311f58fa7804ec52be96ec49a29" and "3b5c78f53996ec4d9f05068b3cdb4d06f3cad040" have entirely different histories.
f595dcd83d
...
3b5c78f539
1 changed files with 12 additions and 27 deletions
39
main.py
39
main.py
|
@ -42,7 +42,7 @@ def load(variables) -> dict:
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
|
||||||
def cleanTweet(tweet: str) -> str | None:
|
def cleanTweet(tweet: str) -> str:
|
||||||
"""Remove all unwanted elements from the tweet"""
|
"""Remove all unwanted elements from the tweet"""
|
||||||
# Convert to lower case
|
# Convert to lower case
|
||||||
tweet = tweet.lower()
|
tweet = tweet.lower()
|
||||||
|
@ -56,7 +56,7 @@ def cleanTweet(tweet: str) -> str | None:
|
||||||
tweet = sub(r"#\S+", " ", tweet)
|
tweet = sub(r"#\S+", " ", tweet)
|
||||||
else:
|
else:
|
||||||
# Too much hashtags in the tweet -> so ignore it
|
# Too much hashtags in the tweet -> so ignore it
|
||||||
return None
|
return ""
|
||||||
# Remove usernames
|
# Remove usernames
|
||||||
tweet = sub(r"@\S+", " ", tweet)
|
tweet = sub(r"@\S+", " ", tweet)
|
||||||
# Remove everything who isn't a letter/number/space
|
# Remove everything who isn't a letter/number/space
|
||||||
|
@ -109,20 +109,18 @@ class Listener(StreamingClient):
|
||||||
# Log
|
# Log
|
||||||
if keys["VERBOSE"]:
|
if keys["VERBOSE"]:
|
||||||
infoLastWord = "dernier mot : "
|
infoLastWord = "dernier mot : "
|
||||||
newline = "\n"
|
if len(lastWord) > 0:
|
||||||
match lastWord:
|
infoLastWord += f"dernier mot : {lastWord.split()[-1:][0]}"
|
||||||
case None:
|
else:
|
||||||
infoLastWord += "tweet ignoré car trop de hashtags"
|
infoLastWord += "tweet ignoré car trop de hashtags"
|
||||||
case w if len(w) == 0:
|
|
||||||
infoLastWord += "tweet pas intéressant"
|
|
||||||
case _:
|
|
||||||
infoLastWord += f"dernier mot : {lastWord.split()[-1:][0]}"
|
|
||||||
newline = ""
|
|
||||||
print(
|
print(
|
||||||
f"Tweet trouvé de {username} ({infoLastWord})...{newline}", end=" ")
|
f"Tweet trouvé de {username} ({infoLastWord})...", end=" ")
|
||||||
|
|
||||||
# Ignore a tweet
|
# Hashtag tweet
|
||||||
if lastWord == None or len(lastWord) == 0:
|
if len(lastWord) == 0:
|
||||||
|
if keys["VERBOSE"]:
|
||||||
|
# Newline
|
||||||
|
print("")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fetch the last word of the tweet
|
# Fetch the last word of the tweet
|
||||||
|
@ -174,19 +172,6 @@ class Listener(StreamingClient):
|
||||||
if keys["VERBOSE"]:
|
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 on_request_error(self, status_code):
|
|
||||||
print(f"{errorMessage[:-2]} ({status_code}) !", end=" ")
|
|
||||||
match status_code:
|
|
||||||
case 420:
|
|
||||||
if keys["VERBOSE"]:
|
|
||||||
print("Déconnecter du flux.")
|
|
||||||
case 429:
|
|
||||||
if keys["VERBOSE"]:
|
|
||||||
print("En attente de reconnexion...")
|
|
||||||
case _:
|
|
||||||
print("\n")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def repeater(word: str) -> str:
|
def repeater(word: str) -> str:
|
||||||
"""Formating a word who need to be repeated"""
|
"""Formating a word who need to be repeated"""
|
||||||
|
|
Reference in a new issue