don't check the tweet date and doublecheck for retweets

This commit is contained in:
Mylloon 2022-08-07 22:06:41 +02:00
parent 52525cab51
commit a40866e736
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

17
main.py
View file

@ -5,7 +5,6 @@ from random import choice
from re import findall, sub from re import findall, sub
from dotenv import load_dotenv from dotenv import load_dotenv
from pytz import timezone
from tweepy import Client, StreamingClient, StreamRule, Tweet from tweepy import Client, StreamingClient, StreamRule, Tweet
@ -95,8 +94,8 @@ class Listener(StreamingClient):
print(f"Raison : {notice['reason']}") print(f"Raison : {notice['reason']}")
def on_tweet(self, tweet: Tweet): def on_tweet(self, tweet: Tweet):
# Verify the age of the tweet # Check if the tweet is not a retweet
if seniority(tweet.created_at): if not tweet.text.startswith("RT @"):
# Fetch the last word of the tweet # Fetch the last word of the tweet
tweet.username: str = self.client.get_user( tweet.username: str = self.client.get_user(
id=tweet.author_id, user_auth=True).data.username id=tweet.author_id, user_auth=True).data.username
@ -194,18 +193,6 @@ def getFriends(client: Client, users: list[str]) -> list:
return friends_list[0] return friends_list[0]
def seniority(date: datetime) -> bool:
"""Return True only if the given string date is less than one day old"""
# Convert string format to datetime format
datetimeObject = datetime.strptime(date, "%a %b %d %H:%M:%S +0000 %Y")
# Twitter give us an UTC time
datetimeObject = datetimeObject.replace(tzinfo=timezone("UTC"))
# time now in UTC minus the time we got to get the age of the date
age = datetime.now(timezone("UTC")) - datetimeObject
# False if older than a day, else True
return False if age.days >= 1 else True
def createBaseTrigger(lists: list[list]) -> list: def createBaseTrigger(lists: list[list]) -> list:
"""Merges all given lists into one""" """Merges all given lists into one"""
listing = [] listing = []