J'ai essayé de faire un bot qui répond automatiquement aux gens disant : "quoi" "feur" (très mauvaise blague française) en python avec l'API tweeter. (Je ne suis pas un développeur python ne me blâmez pas, je suis un développeur php)
Voici l'erreur que j'obtiens : AttributeError: le module 'tweepy' n'a pas d'attribut 'StreamListener'
Pourriez-vous m'aider à le fixer?
Voici le code et merci d'avance (au passage le config.py comporte tout ce qu'il faut c'est juste que je voulais pas montrer mes clés d'api) :
import tweepy
from config import consumer_key, consumer_secret, access_token, access_token_secret, image_path, tweet_limit
# Authenticate
try:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
except tweepy.error.TweepError as e:
print("Error: Failed to authenticate with Twitter API. Check your credentials in config.py")
print(e)
exit()
# Create API object
api = tweepy.API(auth)
# Open the image file
try:
image = open(image_path, "rb")
except FileNotFoundError as e:
print("Error: Image file not found. Make sure image.jpg exist in the same directory as the script.")
print(e)
exit()
class MyStreamListener(tweepy.StreamListener):
def __init__(self):
self.tweet_count = 0
def on_status(self, status):
if "feur" in status.text or "feur!" in status.text or "f1ur" in status.text:
if self.tweet_count < tweet_limit:
try:
api.update_with_media(image_path, status=status.user.screen_name + " -me ta geule", in_reply_to_status_id=status.id)
self.tweet_count += 1
except tweepy.error.TweepError as e:
print("Error: Failed to send tweet.")
print(e)
else:
stream.disconnect()
# Create stream
myStreamListener = MyStreamListener()
stream = tweepy.Stream(auth, myStreamListener)
# Start stream
try:
stream.filter(track=["feur", "feur!", "f1ur"])
except tweepy.error.TweepError as e:
print("Error: Failed to start stream.")
print(e)
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.