Compare commits
2 commits
3b5c78f539
...
f595dcd83d
Author | SHA1 | Date | |
---|---|---|---|
f595dcd83d | |||
dcda3d107e |
1 changed files with 27 additions and 12 deletions
37
main.py
37
main.py
|
@ -42,7 +42,7 @@ def load(variables) -> dict:
|
|||
return keys
|
||||
|
||||
|
||||
def cleanTweet(tweet: str) -> str:
|
||||
def cleanTweet(tweet: str) -> str | None:
|
||||
"""Remove all unwanted elements from the tweet"""
|
||||
# Convert to lower case
|
||||
tweet = tweet.lower()
|
||||
|
@ -56,7 +56,7 @@ def cleanTweet(tweet: str) -> str:
|
|||
tweet = sub(r"#\S+", " ", tweet)
|
||||
else:
|
||||
# Too much hashtags in the tweet -> so ignore it
|
||||
return ""
|
||||
return None
|
||||
# Remove usernames
|
||||
tweet = sub(r"@\S+", " ", tweet)
|
||||
# Remove everything who isn't a letter/number/space
|
||||
|
@ -109,18 +109,20 @@ class Listener(StreamingClient):
|
|||
# Log
|
||||
if keys["VERBOSE"]:
|
||||
infoLastWord = "dernier mot : "
|
||||
if len(lastWord) > 0:
|
||||
infoLastWord += f"dernier mot : {lastWord.split()[-1:][0]}"
|
||||
else:
|
||||
newline = "\n"
|
||||
match lastWord:
|
||||
case None:
|
||||
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(
|
||||
f"Tweet trouvé de {username} ({infoLastWord})...", end=" ")
|
||||
f"Tweet trouvé de {username} ({infoLastWord})...{newline}", end=" ")
|
||||
|
||||
# Hashtag tweet
|
||||
if len(lastWord) == 0:
|
||||
if keys["VERBOSE"]:
|
||||
# Newline
|
||||
print("")
|
||||
# Ignore a tweet
|
||||
if lastWord == None or len(lastWord) == 0:
|
||||
return
|
||||
|
||||
# Fetch the last word of the tweet
|
||||
|
@ -172,6 +174,19 @@ class Listener(StreamingClient):
|
|||
if keys["VERBOSE"]:
|
||||
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:
|
||||
"""Formating a word who need to be repeated"""
|
||||
|
|
Reference in a new issue