Last active
June 16, 2018 06:18
-
-
Save Sebastian-Nielsen/f57244bad3882b0232c04ef4c775cb29 to your computer and use it in GitHub Desktop.
A python bot that automatically joins contests on twitter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy, random, colorama | |
from time import sleep | |
from colorama import init, Fore, Back, Style | |
from time import ctime | |
update_messages = ['I am having a great day today! :)', 'What a wonderful day today.', 'Feeling good #excellent :D', 'Having fun today', 'Why are pugs so cute?', 'I am bored :(', 'Watching a movie tonight.', 'I hope I win this contest #FeelsGoodMan', 'I Love Cake #cake', 'Much memes everywhere', 'Why u do dis to me :( Feelsbadman', 'Icecream is the best thing in the world!', 'Have a nice day everyone!', 'I am feeling tired today :/', 'I just joined a giveaway #Feeling lucky :D', 'Icecream is the best thing in the world! :D', 'Hell yeah, getting pizza tonight #FeelsGoodMan', 'Lmao, I got shit on my shoe.', 'I got a lot of homework today to do. :( #Homework #FML','I got a lot of homework today to do. :( #Homework #FML'] | |
hashtags = ['#Follow #WIN', '#COMPETITION', '#giveaway', '#win',] | |
consumer_key = '' # WRITE_HERE | |
consumer_secret = '' # WRITE_HERE | |
access_token = '' # WRITE_HERE | |
access_secret = '' # WRITE_HERE | |
your_username = '' # WRITE_HERE | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_secret) | |
api = tweepy.API(auth) | |
search = '#rt ' + random.choice(hashtags) | |
print('Searching for:', search) | |
init() | |
for tweet in tweepy.Cursor(api.search, q=search, rpp=100).items(): | |
print(ctime()) | |
print(Back.MAGENTA+Style.BRIGHT+ Fore.WHITE + '\n\nFound tweet by: @'+tweet.user.screen_name) | |
print(Back.GREEN + str(tweet.text.encode('UTF-8'))) | |
if tweet.user.screen_name == your_username: | |
print('Found tweet posted by bot, skipping..') | |
continue | |
sleep(4) | |
try: | |
if (tweet.retweeted == False) and (tweet.favorited == False): | |
tweet.retweet() | |
print(Fore.BLUE+Style.BRIGHT+'retweeted') | |
sleep(10 * random.uniform(0.6, 1.8)) | |
tweet.favorite() | |
print('liked') | |
if tweet.user.follow() == False: | |
sleep(12) | |
tweet.user.follow() | |
print('Followed user') | |
else: | |
print('Already following') | |
print(Fore.YELLOW+'----sleeping----') | |
sleep(900 * random.uniform(1.5, 1.7)) | |
# 10% chance to update the status - I suppose it make the bot seem more human | |
if random.choice([0,0,0,0,0,0,0,0,0,1]): | |
text = random.choice(update_messages) | |
print(Fore.RED+'Updater status med teksten:\n'+text) | |
api.update_status(text) | |
sleep(60) | |
except tweepy.TweepError as e: | |
sleep(900 * random.uniform(1, 1.5)) | |
print(e) | |
except ReadTimeoutError as e: | |
print(e) |
Does the hashtags necessary need to be hashtags? ex.hashtags = ['#Follow #WIN', '#COMPETITION', '#giveaway', '#win',]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am playing around with the tweepy library - I have no idea if it's actually necessary to update the status now and then. I did it to make the bot seem more human.