Okay, so I have this bot I am making for twitter. The goal of the bot is to search for tweets starting with "I'm" and then I want it to copy everything that comes after "I'm." Then respond with "Hi ____________, I'm Dad!" But currently, I am having a key error for my variable in the tweet. I have no idea how to fix this Key Error, at all. Then, I don't know how to make it actually say whatever comes after "I'm" as it automatically just says "Hi I'm Dad" and then the rest of the tweet, but I have yet to test the newest version because of this Key Error.
Here's my code
import tweepy
import tweepy as tt
import tim
import sys
import importlib
from importlib import reload
from collections import defaultdict
importlib.reload(sys)
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''
auth = tt.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tt.API(auth)
search_query = "I'm"
user = api.me()
print(user.name)
max_tweets = 100
for tweet in tweepy.Cursor(api.search, q=search_query, tweet_mode='extended').items(max_tweets):
t = tweet.full_text
answer = "@{name} Hi {t}, I'm dad!".format(name=tweet.user.screen_name)
api.update_status(in_reply_to_status_id=answer)
print("Reply:", answer)
time.sleep(0)
-----------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexo\PycharmProjects\Twitter Daddy\Twitter Daddy.py", line 29, in module>
answer = "@{name} Hi {t}, I'm dad!".format(name=tweet.user.screen_name)
KeyError: 't'
All help is appreciated and thank you very much!
What I have tried:
A lot of things, I've been working on this for about 12 hours. Nothing too relevant as I am new.