opti if order

This commit is contained in:
Mylloon 2021-08-04 14:50:09 +02:00
parent 2d3c60bed9
commit 0271c1c6a0

View file

@ -31,21 +31,21 @@ class Listener(StreamListener):
def on_status(self, status): def on_status(self, status):
"""Answer to tweets.""" """Answer to tweets."""
if status._json["user"]["id"] in self.listOfFriendsID:
if seniority(status._json["created_at"]): if seniority(status._json["created_at"]):
tweetText = sub(r'https?:\/\/\S+| +?\?|\?| +?\!| ?\!|-|~', '', status._json["text"]) tweetText = sub(r'https?:\/\/\S+| +?\?|\?| +?\!| ?\!|-|~', '', status._json["text"])
if status._json["user"]["id"] in self.listOfFriendsID:
lastWord = tweetText.split()[-1:][0].lower() lastWord = tweetText.split()[-1:][0].lower()
if lastWord in universalBase: if lastWord in universalBase:
try:
if lastWord in quoiBase: if lastWord in quoiBase:
answer = feur answer = feur
elif lastWord in ouiBase: elif lastWord in ouiBase:
answer = stiti answer = stiti
elif lastWord in nonBase: elif lastWord in nonBase:
answer = bril answer = bril
else: else: # temporary
print(f"{errorMessage} I didn't know how to answer.") print(f"{errorMessage} I didn't know how to answer.")
return return
try:
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)
print(f"{status._json['user']['screen_name']} s'est fait {answer[0]} !") print(f"{status._json['user']['screen_name']} s'est fait {answer[0]} !")
except Exception as error: except Exception as error: