chir.py- twitter bot that earns bitcoin via ppc links |
git clone git://git.acid.vegas/chir.py.git |
Log | Files | Refs | Archive | README | LICENSE |
twitter.py (6132B)
1 #!/usr/bin/env python 2 # Chir.py Twitter Bot - Developed by acidvegas in Python (https://acid.vegas/chir.py) 3 # twitter.py 4 5 import random 6 import threading 7 import time 8 9 import tweepy 10 11 import config 12 import debug 13 import functions 14 15 api = None 16 me = None 17 18 def login(): 19 global api, me 20 try: 21 auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret) 22 auth.set_access_token(config.access_token, config.access_token_secret) 23 api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) 24 me = api.me() 25 except tweepy.TweepError: 26 debug.error_exit('Failed to login to Twitter!') 27 28 def stats(): 29 debug.action('SceenName\t: %s' % me.screen_name) 30 debug.action('Registered\t: %s' % me.created_at) 31 debug.action('Favorites\t: %s' % me.favourites_count) 32 debug.action('Following\t: %s' % me.friends_count) 33 debug.action('Followers\t: %s' % me.followers_count) 34 debug.action('Tweets\t\t: %s' % me.statuses_count) 35 36 class boost_loop(threading.Thread): 37 def __init__(self): 38 threading.Thread.__init__(self) 39 def run(self): 40 while True: 41 try: 42 if 'boost_tweet' in locals(): api.destroy_status(boost_tweet.id) 43 boost_tweet = api.update_status('Support our Twitter! #' + ' #'.join(config.boost_keywords)) 44 debug.alert('Re-posted boost tweet.') 45 except tweepy.TweepError as ex: 46 debug.error('Error occured in the boost loop', ex) 47 finally: 48 random.shuffle(config.boost_keywords) 49 time.sleep(60*5) 50 51 class favorite_loop(threading.Thread): 52 def __init__(self): 53 threading.Thread.__init__(self) 54 def run(self): 55 while True: 56 try: 57 for tweet in tweepy.Cursor(api.home_timeline, exclude_replies=True).items(50): 58 if tweet.user.screen_name != me.screen_name: 59 if not tweet.favorited: 60 if random.choice([True, False, False, False, False]): 61 api.create_favorite(tweet.id) 62 debug.alert('Favorited a friends tweet!') 63 time.sleep(30) 64 except tweepy.TweepError as ex: 65 debug.error('Error occured in the favorite loop!', ex) 66 finally: 67 time.sleep(60*15) 68 69 class follow_loop(threading.Thread): 70 def __init__(self): 71 threading.Thread.__init__(self) 72 def run(self): 73 while True: 74 try: 75 followers = api.followers_ids(me.screen_name) 76 friends = api.friends_ids(me.screen_name) 77 if me.friends_count / me.followers_count == 3: 78 debug.action('Following to follower ratio is off! Starting the unfollow loop...') 79 unfollow_loop() 80 for follower in followers: 81 if not follower in friends: 82 api.create_friendship(follower) 83 api.send_direct_message(screen_name=follower, text='Thanks for following our Twitter. Be sure to share us with your friends & keep up with the latest sports news!') 84 debug.alert('Followed back a follower!') 85 time.sleep(30) 86 except tweepy.TweepError as ex: 87 debug.error('Error occured in the follow loop!', ex) 88 finally: 89 time.sleep(60*15) 90 91 def main_loop(): 92 boost_loop().start() 93 favorite_loop().start() 94 follow_loop().start() 95 news_loop().start() 96 search_loop().start() 97 98 class news_loop(threading.Thread): 99 def __init__(self): 100 threading.Thread.__init__(self) 101 def run(self): 102 while True: 103 try: 104 news = functions.get_news() 105 tweets = list() 106 for item in tweepy.Cursor(api.user_timeline, exclude_replies=True).items(50): 107 tweets.append(item.text.split('... ')[0]) 108 time.sleep(2) 109 for item in news: 110 split = item.split('... ')[0] 111 if split not in tweets: 112 api.update_status(item) 113 debug.alert('A tweet has been posted.') 114 time.sleep(60*5) 115 except tweepy.TweepError as ex: 116 debug.error('Error occured in the news loop', ex) 117 finally: 118 time.sleep(60*15) 119 120 class search_loop(threading.Thread): 121 def __init__(self): 122 threading.Thread.__init__(self) 123 def run(self): 124 query_keywords = list() 125 for item in config.news_keywords: 126 query_keywords = query_keywords + list(config.news_keywords[item]) 127 query_keywords = query_keywords + config.boost_keywords 128 while True: 129 try: 130 query = random.choice(query_keywords) 131 for item in api.search(q='#' + query, count=50, lang='en', result_type='mixed'): 132 if not item.user.following and not item.favorited: 133 try: 134 api.create_favorite(item.id) 135 api.create_friendship(item.user.screen_name) 136 debug.alert('Followed a similar twitter!') 137 except tweepy.TweepError as ex: 138 debug.error('Unknown error occured in the search loop!', ex) 139 time.sleep(30) 140 except tweepy.TweepError as ex: 141 debug.error('Error occured in the search loop!', ex) 142 finally: 143 time.sleep(60*15) 144 145 def unfollow_loop(): 146 try: 147 followers = api.followers_ids(me.screen_name) 148 friends = api.friends_ids(me.screen_name) 149 for friend in friends: 150 if friend not in followers: 151 api.destroy_friendship(friend) 152 debug.alert('Unfollowed an unsupporting friend!') 153 time.sleep(30) 154 except tweepy.TweepError as ex: 155 debug.error('Error occured in the unfollow loop!', ex)