set a limit of age (1day)
This commit is contained in:
parent
f711671129
commit
4ef15d2e32
1 changed files with 22 additions and 15 deletions
25
main.py
25
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,21 +21,27 @@ 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"]):
|
||||||
|
tweetText = sub(r' +?\?|\?| +?\!| ?\!', '', status._json["text"])
|
||||||
if tweetText.endswith(tuple(quoi)):
|
if tweetText.endswith(tuple(quoi)):
|
||||||
try:
|
|
||||||
if status._json["user"]["screen_name"] in friends:
|
if status._json["user"]["screen_name"] in friends:
|
||||||
|
try:
|
||||||
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
self.api.update_status(status = choice(feur), in_reply_to_status_id = status._json["id"], auto_populate_reply_metadata = True)
|
||||||
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
print(f"{status._json['user']['screen_name']} est passé au coiffeur !")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
print(f"Error happens! {error}")
|
||||||
pass
|
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."""
|
||||||
auth = OAuthHandler(consumerKey, consumerSecret)
|
auth = OAuthHandler(consumerKey, consumerSecret)
|
||||||
|
@ -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