Currently, I am having trouble creating a twitterbot on Tweepy.
I'd like to write a program where I learn tweets containing certain strings at regular intervals and tweet the sentences contained in those tweets by myself instead of RT.
got exception:
'SearchResults' object has no attribute' text'
If the text does not exist, it will appear.Is it impossible to take out a sentence and tweet the content?
The source code is as follows
#coding:UTF-8
import tweet
import time
while True:
CONSUMER_KEY = '**********'
CONSUMER_SECRET = '********************'
auth=tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
ACCESS_TOKEN='**************'
ACCESS_SECRET = '********************'
auth.set_access_token(ACCESS_TOKEN,ACCESS_SECRET)
api=tweepy.API(auth)
search=api.search(q='#paperplane', lang='ja', count=10)
try:
api.update_status(search.text)
exceptAttributeError as:
print("got exception:")
print(e)
time.sleep(30)
http://docs.tweepy.org/en/v3.5.0/api.html?highlight=search
Help Methods API.search(q[,lang][,locale][,rpp][,page][,
since_id][,geocode][,show_user]) Returns tweets that match a
specified query.
Return type:list of SearchResult objects
The return value of the API.search method in tweet seems to return a list of SearchResult objects.
So I think you can do it like this.
search=api.search(q='#paperplane',lang='ja',count=10)
For in search:
api.update_status(s.text)
Now you know the tweet and the username that tweeted it
search=api.search(q='#a',lang='ja',count=2)
For in search:
print(s.author._json['screen_name'])
print(s.text)
© 2024 OneMinuteCode. All rights reserved.