1
mirror of git://git.acid.vegas/booster.git synced 2024-11-22 07:46:37 +00:00

minor update to prepair for major cleanup

This commit is contained in:
Dionysus 2019-08-02 02:56:47 -04:00
parent 624276b818
commit d9f8aa3cce
No known key found for this signature in database
GPG Key ID: 05114B46832BDBDB
5 changed files with 190 additions and 215 deletions

View File

@ -1,8 +1,8 @@
###### Requirments ## Requirments
* [Tweepy](http://pypi.python.org/pypi/tweepy) - [Tweepy](http://pypi.python.org/pypi/tweepy)
###### Instructions ## Instructions
Register a Twitter account, and [sign up](http://dev.twitter.com/apps/new) for a new developer application. Create a Twitter account & [sign up](http://dev.twitter.com/apps/new) for a new developer application.
Go to your new application settings "Keys and Access Tokens" tab. Go to your new application settings "Keys and Access Tokens" tab.
@ -16,7 +16,7 @@ Change your access to "Read, Write and Access direct messages".
Edit your `config.py` and change the Twitter API settings. Edit your `config.py` and change the Twitter API settings.
###### Mirrors ## Mirrors
- [acid.vegas](https://acid.vegas/booster) *(main)* - [acid.vegas](https://acid.vegas/booster) *(main)*
- [SuperNETs](https://git.supernets.org/acidvegas/booster) - [SuperNETs](https://git.supernets.org/acidvegas/booster)
- [GitHub](https://github.com/acidvegas/booster) - [GitHub](https://github.com/acidvegas/booster)

View File

@ -10,9 +10,9 @@ import debug
debug.info() debug.info()
if not debug.check_version(3): if not debug.check_version(3):
debug.error_exit('Requires Python version 3 to run!') debug.error_exit('Requires Python version 3 to run!')
if debug.check_privileges(): if debug.check_privileges():
debug.error_exit('Do not run as admin/root!') debug.error_exit('Do not run as admin/root!')
debug.check_imports() debug.check_imports()
debug.check_config() debug.check_config()
import twitter import twitter

View File

@ -10,84 +10,61 @@ import time
import config import config
def action(msg): def action(msg):
print('%s | [#] - %s' % (get_time(), msg)) print(f'{get_time()} | [#] - {msg}')
def alert(msg): def alert(msg):
print('%s | [+] - %s' % (get_time(), msg)) print(f'{get_time()} | [+] - {msg}')
def check_config(): def check_config():
for item in (config.consumer_key, config.consumer_secret, config.access_token, config.access_token_secret): if 'CHANGEME' in (config.consumer_key, config.consumer_secret, config.access_token, config.access_token_secret):
if item == 'CHANGEME': error_exit('Edit your config file!')
error_exit('Edit your config file!')
def check_imports(): def check_imports():
try: try:
import tweepy import tweepy
except ImportError: except ImportError:
error_exit('Failed to import the Tweepy library! (http://pypi.python.org/pypi/tweepy)') error_exit('Failed to import the Tweepy library! (http://pypi.python.org/pypi/tweepy)')
def check_privileges(): def check_privileges():
if check_windows(): if check_windows():
if ctypes.windll.shell32.IsUserAnAdmin() != 0: return True if ctypes.windll.shell32.IsUserAnAdmin() != 0 else return False
return True else:
else: return True if os.getuid() == 0 or os.geteuid() == 0 else return False
return False
else:
if os.getuid() == 0 or os.geteuid() == 0:
return True
else:
return False
def check_version(major): def check_version(major):
if sys.version_info.major == major: return True if sys.version_info.major == major else return False
return True
else:
return False
def check_windows(): def check_windows():
if os.name == 'nt': return True if os.name == 'nt' else return False
return True
else:
return False
def clear(): def clear():
if check_windows(): os.system('cls') if check_windows() else os.system('clear')
os.system('cls')
else:
os.system('clear')
def error(msg, reason=None): def error(msg, reason=None):
if reason: print(f'{get_time()} | [!] - {msg} ({str(reason)})') if reason else print(f'{get_time()} | [!] - {msg}')
print('%s | [!] - %s (%s)' % (get_time(), msg, str(reason)))
else:
print('%s | [!] - %s' % (get_time(), msg))
def error_exit(msg): def error_exit(msg):
raise SystemExit('%s | [!] - %s' % (get_time(), msg)) raise SystemExit(f'{get_time()} | [!] - {msg}')
def get_time(): def get_time():
return time.strftime('%I:%M:%S') return time.strftime('%I:%M:%S')
def get_windows(): def get_windows():
if os.name == 'nt': return True if os.name == 'nt' else False
return True
else:
return False
def info(): def info():
clear() clear()
print(''.rjust(56, '#')) print(''.rjust(56, '#'))
print('#{0}#'.format(''.center(54))) print('#{0}#'.format(''.center(54)))
print('#{0}#'.format('Booster Twitter Bot'.center(54))) print('#{0}#'.format('Booster Twitter Bot'.center(54)))
print('#{0}#'.format('Developed by acidvegas in Python 3'.center(54))) print('#{0}#'.format('Developed by acidvegas in Python'.center(54)))
print('#{0}#'.format('https://acid.vegas/booster'.center(54))) print('#{0}#'.format('https://acid.vegas/booster'.center(54)))
print('#{0}#'.format(''.center(54))) print('#{0}#'.format(''.center(54)))
print(''.rjust(56, '#')) print(''.rjust(56, '#'))
def keep_alive(): def keep_alive():
try: try:
while True: while True:
input('') input('')
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit() sys.exit()

View File

@ -7,17 +7,15 @@ import random
import urllib.request import urllib.request
def get_day(): def get_day():
return datetime.datetime.today().weekday() return datetime.datetime.today().weekday()
def get_source(url): def get_source(url):
req = urllib.request.Request(url) req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)') req.add_header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')
source = urllib.request.urlopen(req, timeout=10) source = urllib.request.urlopen(req, timeout=10)
charset = source.headers.get_content_charset() charset = source.headers.get_content_charset()
if charset: if charset:
return source.read().decode(charset) return source.read().decode(charset) if charset else return source.read().decode()
else:
return source.read().decode()
def random_int(min, max): def random_int(min, max):
return random.randint(min, max) return random.randint(min, max)

View File

@ -13,156 +13,156 @@ import debug
import functions import functions
class Booster(object): class Booster(object):
def __init__(self): def __init__(self):
self.api = None self.api = None
self.me = None self.me = None
self.favorites = 0 self.favorites = 0
self.max_favorites = config.max_favorites self.max_favorites = config.max_favorites
self.follows = 0 self.follows = 0
self.max_follows = config.max_follows self.max_follows = config.max_follows
self.messages = 0 self.messages = 0
self.max_messages = config.max_messages self.max_messages = config.max_messages
self.tweets = 0 self.tweets = 0
self.max_tweets = config.max_tweets self.max_tweets = config.max_tweets
self.unfollows = 0 self.unfollows = 0
self.max_unfollows = config.max_unfollows self.max_unfollows = config.max_unfollows
self.send_message = config.send_message self.send_message = config.send_message
self.message = config.message self.message = config.message
def run(self): def run(self):
self.login() self.login()
threading.Thread(target=self.loop_boost).start() threading.Thread(target=self.loop_boost).start()
threading.Thread(target=self.loop_favorite).start() threading.Thread(target=self.loop_favorite).start()
threading.Thread(target=self.loop_follow).start() threading.Thread(target=self.loop_follow).start()
threading.Thread(target=self.loop_search).start() threading.Thread(target=self.loop_search).start()
# threading.Thread(target=self.loop_trend).start() threading.Thread(target=self.loop_trend).start()
def login(self): def login(self):
try: try:
auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret) auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret)
auth.set_access_token(config.access_token, config.access_token_secret) auth.set_access_token(config.access_token, config.access_token_secret)
self.api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) self.api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
self.me = self.api.me() self.me = self.api.me()
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error_exit('Failed to login to Twitter! ({0})'.format(str(ex))) debug.error_exit('Failed to login to Twitter! ({0})'.format(str(ex)))
def loop_boost(self): def loop_boost(self):
while True: while True:
try: try:
if 'boost_tweet' in locals(): self.api.destroy_status(boost_tweet.id) if 'boost_tweet' in locals(): self.api.destroy_status(boost_tweet.id)
boost_tweet = self.api.update_status('RT for followers! #' + ' #'.join(config.boost_keywords)) boost_tweet = self.api.update_status('RT for followers! #' + ' #'.join(config.boost_keywords))
self.tweets += 1 self.tweets += 1
debug.alert('Re-posted boost tweet.') debug.alert('Re-posted boost tweet.')
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the boost loop', ex) debug.error('Error occured in the boost loop', ex)
finally: finally:
random.shuffle(config.boost_keywords) random.shuffle(config.boost_keywords)
time.sleep(60*5) time.sleep(60*5)
def loop_favorite(self): def loop_favorite(self):
while True: while True:
try: try:
for tweet in tweepy.Cursor(api.home_timeline, exclude_replies=True).items(50): for tweet in tweepy.Cursor(self.api.home_timeline, exclude_replies=True).items(50):
if tweet.user.screen_name != me.screen_name: if tweet.user.screen_name != self.me.screen_name:
if not tweet.favorited: if not tweet.favorited:
if random.choice((True, False, False, False, False)): if random.choice((True, False, False, False, False)):
api.create_favorite(tweet.id) self.api.create_favorite(tweet.id)
self.favorites += 1 self.favorites += 1
debug.alert('Favorited a friends tweet!') debug.alert('Favorited a friends tweet!')
time.sleep(30) time.sleep(30)
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the favorite loop!', ex) debug.error('Error occured in the favorite loop!', ex)
finally: finally:
time.sleep(60*15) time.sleep(60*15)
def loop_follow(self): def loop_follow(self):
while True: while True:
try: try:
followers = api.followers_ids(me.screen_name) followers = self.api.followers_ids(self.me.screen_name)
friends = api.friends_ids(me.screen_name) friends = self.api.friends_ids(self.me.screen_name)
non_friends = [friend for friend in followers if friend not in friends] non_friends = [friend for friend in followers if friend not in friends]
debug.action('Following back {0} supporters...'.format(len(non_friends))) debug.action('Following back {0} supporters...'.format(len(non_friends)))
for follower in non_friends: for follower in non_friends:
api.create_friendship(follower) self.api.create_friendship(follower)
self.follows += 1 self.follows += 1
debug.alert('Followed back a follower!') debug.alert('Followed back a follower!')
if self.follows >= self.max_follows: if self.follows >= self.max_follows:
break break
if self.send_message: if self.send_message:
api.send_direct_message(screen_name=follower, text=self.message) self.api.send_direct_message(screen_name=follower, text=self.message)
time.sleep(30) time.sleep(30)
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the follow loop!', ex) debug.error('Error occured in the follow loop!', ex)
finally: finally:
time.sleep(60*15) time.sleep(60*15)
def loop_search(self): def loop_search(self):
while True: while True:
try: try:
query = random.choice(config.boost_keywords) query = random.choice(config.boost_keywords)
for item in api.search(q='#' + query, count=50, lang='en', result_type='recent'): for item in self.api.search(q='#' + query, count=50, lang='en', result_type='recent'):
if not item.user.following and not item.favorited: if not item.user.following and not item.favorited:
try: try:
api.create_favorite(item.id) self.api.create_favorite(item.id)
api.create_friendship(item.user.screen_name) self.api.create_friendship(item.user.screen_name)
self.favorites += 1 self.favorites += 1
self.follows += 1 self.follows += 1
debug.alert('Followed a booster twitter!') debug.alert('Followed a booster twitter!')
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Unknown error occured in the search loop!', ex) debug.error('Unknown error occured in the search loop!', ex)
time.sleep(30) time.sleep(30)
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the search loop!', ex) debug.error('Error occured in the search loop!', ex)
finally: finally:
time.sleep(60*15) time.sleep(60*15)
def loop_trend(self): def loop_trend(self):
while True: while True:
try: try:
trends = self.api.trends_place(str(config.woeid)) trends = self.api.trends_place(str(config.woeid))
hashtags = [x['name'] for x in trends[0]['trends'] if x['name'].startswith('#')] hashtags = [x['name'] for x in trends[0]['trends'] if x['name'].startswith('#')]
for trend in hashtags: for trend in hashtags:
for item in self.api.search(q=trend, count=5, lang='en', result_type='top'): for item in self.api.search(q=trend, count=5, lang='en', result_type='top'):
#self.api.update_status(item.tweet) # FIX THIS PART self.api.update_status(item.tweet)
time.sleep(30) time.sleep(30)
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the trend loop!', ex) debug.error('Error occured in the trend loop!', ex)
finally: finally:
time.sleep(60*15) time.sleep(60*15)
def loop_unfollow(self): def loop_unfollow(self):
try: try:
followers = self.api.followers_ids(self.me.screen_name) followers = self.api.followers_ids(self.me.screen_name)
friends = self.api.friends_ids(self.me.screen_name) friends = self.api.friends_ids(self.me.screen_name)
non_friends = [friend for friend in friends if friend not in followers] non_friends = [friend for friend in friends if friend not in followers]
non_friends.reverse() non_friends.reverse()
debug.action('Unfollowing {0} unsupporting friends...'.format(len(non_friends))) debug.action('Unfollowing {0} unsupporting friends...'.format(len(non_friends)))
for friend in non_friends: for friend in non_friends:
self.api.destroy_friendship(friend) self.api.destroy_friendship(friend)
self.unfollows += 1 self.unfollows += 1
debug.alert('Unfollowed an unsupporting friend!') debug.alert('Unfollowed an unsupporting friend!')
if self.unfollows == self.max_unfollows: if self.unfollows == self.max_unfollows:
break break
else: else:
time.sleep(60*functions.random_int(10,15)) time.sleep(60*functions.random_int(10,15))
except tweepy.TweepError as ex: except tweepy.TweepError as ex:
debug.error('Error occured in the unfollow loop!', ex) debug.error('Error occured in the unfollow loop!', ex)
finally: finally:
self.unfollows = 0 self.unfollows = 0
def ratio_check(self): def ratio_check(self):
if self.follows >= max_follows: if self.follows >= max_follows:
time.sleep(86400) time.sleep(86400)
if me.friends_count >= 2000: if self.me.friends_count >= 2000:
ratio = me.friends_count + (me.followers_count/10) ratio = self.me.friends_count + (self.me.followers_count/10)
if me.friends_count >= ratio: if self.me.friends_count >= ratio:
debug.action('Following to follower ratio is off! Starting the unfollow loop...') debug.action('Following to follower ratio is off! Starting the unfollow loop...')
unfollow_loop() unfollow_loop()
def stats(self): def stats(self):
debug.action('SceenName : ' + self.me.screen_name) debug.action('SceenName : ' + self.me.screen_name)
debug.action('Registered : ' + self.me.created_at) debug.action('Registered : ' + self.me.created_at)
debug.action('Favorites : ' + self.me.favourites_count) debug.action('Favorites : ' + self.me.favourites_count)
debug.action('Following : ' + self.me.friends_count) debug.action('Following : ' + self.me.friends_count)
debug.action('Followers : ' + self.me.followers_count) debug.action('Followers : ' + self.me.followers_count)
debug.action('Tweets : ' + self.me.statuses_count) debug.action('Tweets : ' + self.me.statuses_count)