└── TwitterBot.py /TwitterBot.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | A simple Twitter bot using the Twitter Python library that finds users who tweet about "Christmas gift ideas," 4 | favorites their tweet, follows the users and sends them a friendly tweet with Amazon links of popular gift ideas. 5 | 6 | """ 7 | 8 | import urllib 9 | import simplejson 10 | import twitter 11 | 12 | consumer_key = 'Y6dSH82jVCQvVzrkjk3JQ' 13 | consumer_secret = '4XykXa3D2eqk6pTI8UDUKgjt3GBEV3GYqaKuFe0jD2A' 14 | access_token_key = '983701741-kX9UNcOHw5nY2eDoW0vOJQdVRYtI6dwd2bzASCoD' 15 | access_token_secret = 'eZyBJ5xSBrEZio3NX3Rf99wMlTWJheIhEezPu7BQ4s' 16 | 17 | def searchTweets(query): 18 | search = urllib.urlopen("http://search.twitter.com/search.json?q="+query) 19 | dict = simplejson.loads(search.read()) 20 | return dict 21 | 22 | api = twitter.Api(consumer_key = consumer_key, consumer_secret = consumer_secret, access_token_key = access_token_key, access_token_secret = access_token_secret) 23 | tweets = searchTweets("christmas+gift+ideas&rpp=100&result_type=recent") 24 | msg = 'Internet neighbor! Saw your tweet - here are my Xmas gift ideas! Him: http://amzn.to/TDjghP Her: http://amzn.to/TEWDbY' 25 | 26 | for i in range(len(tweets["results"])): 27 | tweeter = tweets["results"][i]["from_user"] 28 | status = twitter.Api.GetStatus(api, tweets["results"][i]["id"]) 29 | api.CreateFavorite(status) 30 | api.CreateFriendship(tweeter) 31 | api.PostUpdate('@' + tweeter + ' ' + msg) 32 | --------------------------------------------------------------------------------