better handling of invalid tweets
This commit is contained in:
parent
dcda3d107e
commit
f595dcd83d
1 changed files with 14 additions and 12 deletions
26
main.py
26
main.py
|
@ -42,7 +42,7 @@ def load(variables) -> dict:
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
|
|
||||||
def cleanTweet(tweet: str) -> str:
|
def cleanTweet(tweet: str) -> str | None:
|
||||||
"""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:
|
||||||
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 ""
|
return None
|
||||||
# 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,18 +109,20 @@ class Listener(StreamingClient):
|
||||||
# Log
|
# Log
|
||||||
if keys["VERBOSE"]:
|
if keys["VERBOSE"]:
|
||||||
infoLastWord = "dernier mot : "
|
infoLastWord = "dernier mot : "
|
||||||
if len(lastWord) > 0:
|
newline = "\n"
|
||||||
infoLastWord += f"dernier mot : {lastWord.split()[-1:][0]}"
|
match lastWord:
|
||||||
else:
|
case None:
|
||||||
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})...", end=" ")
|
f"Tweet trouvé de {username} ({infoLastWord})...{newline}", end=" ")
|
||||||
|
|
||||||
# Hashtag tweet
|
# Ignore a tweet
|
||||||
if len(lastWord) == 0:
|
if lastWord == None or len(lastWord) == 0:
|
||||||
if keys["VERBOSE"]:
|
|
||||||
# Newline
|
|
||||||
print("")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Fetch the last word of the tweet
|
# Fetch the last word of the tweet
|
||||||
|
|
Reference in a new issue