#You are going to iterate through whatever q (whether it be a hashtag #or a word, then items is so you can specify how many items #you want to go through #tweet will contain the ACTUAL tweet, but it has attributes like #user that tweeted it, etc. pnum = 1 for page in tweepy.Cursor(api.search,q = '#enteryourhashtaghere',lang="en").pages(25): print("Page # %d"%pnum) for tweet in page: try: #to make sure that you are not retweeting your own tweets if (tweet.user.id == myBot.id) or (myData.is_stored_b(str(tweet.id))): print("This tweet was already processed.") continue myData.add_data(str(tweet.id)) #printing out users that have tweeted with the hashtag print("\n\nFound tweet by: @",tweet.user.screen_name) #retweeting the tweet if(tweet.retweeted == False) or (tweet.favorited == False): #retweeting tweet.retweet() tweet.favorite() print("Retweeted and favorited the tweet by @ %s" %tweet.user.screen_name) #following the user if tweet.user.following == False: #following tweet.user.follow() print("Followed the user @ %s" %tweet.user.screen_name)
auth = tweepy.OAuthHandler(consumer_key,consumer_secret) auth.set_access_token(access_token,access_token_secret) auth.secure = True api = tweepy.API(auth) myBot = api.get_user(screen_name = '@tutbot') myList = api.get_list("@"+myBot.screen_name,slug='sorry-for-adding-you') myData = DataManager("DataFile.txt") listData = DataManager("listData.txt") count403 = 0 print("Running bot: @" + myBot.screen_name + "\n Using list: " + myList.name + " \n Members count:" + str(myList.member_count) + " Subs count: " + str(myList.subscriber_count)) for tweet in tweepy.Cursor(api.search,q='#Marist').items(): try: if (tweet.user.id == myBot.id) or (myData.is_stored_b(str(tweet.id))): continue myData.add_data(str(tweet.id)) print("\n\nFound tweet by: @" + tweet.user.screen_name) if(tweet.retweeted == False) or (tweet.favorited == False): tweet.retweet() tweet.favorite() print("Retweeted and favorited the tweet") if not listData.is_stored_b(str(tweet.user.id)): #api.add_list_member(screen_name = tweet.user.screen_name, owner_screen_name = myBot.screen_name, list_id = myList.id) listData.add_data(str(tweet.user.id)) print("Added the user to the list") if tweet.user.following == False: tweet.user.follow() print("Followed the user") count403 = 0 except tweepy.TweepError as e: print(e.reason)