Trying to run this twitter python bot. It just basicly needs to setup the tokens (already seted) and hashtag to search and favorite. I'm newbie into coding so i really dunno where i'm going here. Just cloned this code from github and trying to run it. Running python 2.7.2
"""
A simple Twitter bot using the Twitter Python library that finds users who tweet about "Christmas gift ideas,"
favorites their tweet, follows the users and sends them a friendly tweet with Amazon links of popular gift ideas.
"""
import urllib
import simplejson
import twitter
consumer_key = ''
consumer_secret = ''
access_token_key = ''
access_token_secret = ''
def searchTweets(query):
search = urllib.urlopen("http://search.twitter.com/search.json?q="+query)
dict = simplejson.loads(search.read())
return dict
api = twitter.Api(consumer_key = 'consumer_key', consumer_secret = 'consumer_secret', access_token_key = 'access_token_key', access_token_secret = 'access_token_secret')
tweets = searchTweets("hashtag")
msg = "Tweet message"
for i in range(len(tweets["results"])):
tweeter = tweets["results"][i]["from_user"]
status = twitter.Api.GetStatus(api, tweets["results"][i]["id"])
api.CreateFavorite(status)
api.CreateFriendship(tweeter)
api.PostUpdate('@' + tweeter + ' ' + msg)
I've changed the tokens info and stuff, but i'm getting this error:
Traceback (most recent call last):
File "TwitterBot.py", line 26, in <module>
for i in range(len(tweets["results"])):
KeyError: 'results'
What am I doing wrong? I'm using python-twitter
module installed with pip
.