set a limit of age (1day)
This commit is contained in:
parent
f711671129
commit
4ef15d2e32
1 changed files with 22 additions and 15 deletions
37
main.py
37
main.py
|
@ -3,10 +3,8 @@ from os import environ
|
||||||
from tweepy import OAuthHandler, API, StreamListener, Stream
|
from tweepy import OAuthHandler, API, StreamListener, Stream
|
||||||
from re import sub
|
from re import sub
|
||||||
from random import choice
|
from random import choice
|
||||||
|
from datetime import datetime, timedelta
|
||||||
quoi = ["quoi", "koi"]
|
from pytz import timezone
|
||||||
feur = ["feur", "(feur)", "FEUR", "feur lol"]
|
|
||||||
friends = []
|
|
||||||
|
|
||||||
def load(variables):
|
def load(variables):
|
||||||
"""Load env variables."""
|
"""Load env variables."""
|
||||||
|
@ -23,20 +21,26 @@ def load(variables):
|
||||||
class Listener(StreamListener):
|
class Listener(StreamListener):
|
||||||
def __init__(self, api = None):
|
def __init__(self, api = None):
|
||||||
super(Listener, self).__init__()
|
super(Listener, self).__init__()
|
||||||
self.num_tweets = 0
|
|
||||||
self.api = api
|
self.api = api
|
||||||
|
|
||||||
def on_status(self, status):
|
def on_status(self, status):
|
||||||
"""Réponse au tweet"""
|
"""Answer to tweets."""
|
||||||
tweetText = sub(r' ?\?| ?\!', '', status._json["text"])
|
if seniority(status._json["created_at"]):
|
||||||
if tweetText.endswith(tuple(quoi)):
|
tweetText = sub(r' +?\?|\?| +?\!| ?\!', '', status._json["text"])
|
||||||
try:
|
if tweetText.endswith(tuple(quoi)):
|
||||||
if status._json["user"]["screen_name"] in friends:
|
if status._json["user"]["screen_name"] in friends:
|
||||||
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
try:
|
||||||
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
||||||
except Exception as error:
|
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
||||||
print(error)
|
except Exception as error:
|
||||||
pass
|
print(f"Error happens! {error}")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def seniority(date: str):
|
||||||
|
datetimeObject = datetime.strptime(date, '%a %b %d %H:%M:%S +0000 %Y') # Convert String format to datetime format
|
||||||
|
datetimeObject = datetimeObject.replace(tzinfo = timezone('UTC')) # Twitter give us an UTC time
|
||||||
|
age = datetime.now(timezone('UTC')) - datetimeObject # Time now in UTC minus the time we got to get the age of the date
|
||||||
|
return False if age.days >= 1 else True # False if older than a day
|
||||||
|
|
||||||
def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
||||||
"""Main method."""
|
"""Main method."""
|
||||||
|
@ -52,7 +56,7 @@ def main(accessToken, accessTokenSecret, consumerKey, consumerSecret, user):
|
||||||
friends.append(friend._json["screen_name"])
|
friends.append(friend._json["screen_name"])
|
||||||
|
|
||||||
print(f"Scroll sur Twitter avec les abonnés de @{user}...")
|
print(f"Scroll sur Twitter avec les abonnés de @{user}...")
|
||||||
stream.filter(track = quoi, languages=["fr"], is_async = True)
|
stream.filter(track = quoi, languages = ["fr"], is_async = True)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
"""
|
"""
|
||||||
|
@ -63,5 +67,8 @@ if __name__ == '__main__':
|
||||||
--
|
--
|
||||||
PSEUDO is the PSEUDO of the account you want to listen to snipe. A proportion of who s.he follow will be targeted.
|
PSEUDO is the PSEUDO of the account you want to listen to snipe. A proportion of who s.he follow will be targeted.
|
||||||
"""
|
"""
|
||||||
|
quoi = ["quoi", "koi"]
|
||||||
|
feur = ["feur", "(feur)", "FEUR", "feur lol"]
|
||||||
|
friends = []
|
||||||
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDO"])
|
keys = load(["TOKEN", "TOKEN_SECRET", "CONSUMER_KEY", "CONSUMER_SECRET", "PSEUDO"])
|
||||||
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDO"])
|
main(keys["TOKEN"], keys["TOKEN_SECRET"], keys["CONSUMER_KEY"], keys["CONSUMER_SECRET"], keys["PSEUDO"])
|
||||||
|
|
Reference in a new issue