1 | commit d9f8aa3cce0c7c148da8055eab8570a62089e500 |
2 | Author: acidvegas <acid.vegas@acid.vegas> |
3 | Date: Fri Aug 2 02:56:47 2019 -0400 |
4 | |
5 | minor update to prepair for major cleanup |
6 | --- |
7 | README.md | 10 +- |
8 | booster/booster.py | 4 +- |
9 | booster/debug.py | 87 ++++++---------- |
10 | booster/functions.py | 18 ++-- |
11 | booster/twitter.py | 286 +++++++++++++++++++++++++-------------------------- |
12 | 5 files changed, 190 insertions(+), 215 deletions(-) |
13 | |
14 | diff --git a/README.md b/README.md |
15 | index 2a46e03..a2a5e96 100644 |
16 | --- a/README.md |
17 | +++ b/README.md |
18 | @@ -1,8 +1,8 @@ |
19 | -###### Requirments |
20 | -* [Tweepy](http://pypi.python.org/pypi/tweepy) |
21 | +## Requirments |
22 | +- [Tweepy](http://pypi.python.org/pypi/tweepy) |
23 | |
24 | -###### Instructions |
25 | -Register a Twitter account, and [sign up](http://dev.twitter.com/apps/new) for a new developer application. |
26 | +## Instructions |
27 | +Create a Twitter account & [sign up](http://dev.twitter.com/apps/new) for a new developer application. |
28 | |
29 | Go to your new application settings "Keys and Access Tokens" tab. |
30 | |
31 | @@ -16,7 +16,7 @@ Change your access to "Read, Write and Access direct messages". |
32 | |
33 | Edit your `config.py` and change the Twitter API settings. |
34 | |
35 | -###### Mirrors |
36 | +## Mirrors |
37 | - [acid.vegas](https://acid.vegas/booster) *(main)* |
38 | - [SuperNETs](https://git.supernets.org/acidvegas/booster) |
39 | - [GitHub](https://github.com/acidvegas/booster) |
40 | diff --git a/booster/booster.py b/booster/booster.py |
41 | index d28b7d2..7176c93 100644 |
42 | --- a/booster/booster.py |
43 | +++ b/booster/booster.py |
44 | @@ -10,9 +10,9 @@ import debug |
45 | |
46 | debug.info() |
47 | if not debug.check_version(3): |
48 | - debug.error_exit('Requires Python version 3 to run!') |
49 | + debug.error_exit('Requires Python version 3 to run!') |
50 | if debug.check_privileges(): |
51 | - debug.error_exit('Do not run as admin/root!') |
52 | + debug.error_exit('Do not run as admin/root!') |
53 | debug.check_imports() |
54 | debug.check_config() |
55 | import twitter |
56 | diff --git a/booster/debug.py b/booster/debug.py |
57 | index 904f181..8220cc5 100644 |
58 | --- a/booster/debug.py |
59 | +++ b/booster/debug.py |
60 | @@ -10,84 +10,61 @@ import time |
61 | import config |
62 | |
63 | def action(msg): |
64 | - print('%s | [#] - %s' % (get_time(), msg)) |
65 | + print(f'{get_time()} | [#] - {msg}') |
66 | |
67 | def alert(msg): |
68 | - print('%s | [+] - %s' % (get_time(), msg)) |
69 | + print(f'{get_time()} | [+] - {msg}') |
70 | |
71 | def check_config(): |
72 | - for item in (config.consumer_key, config.consumer_secret, config.access_token, config.access_token_secret): |
73 | - if item == 'CHANGEME': |
74 | - error_exit('Edit your config file!') |
75 | + if 'CHANGEME' in (config.consumer_key, config.consumer_secret, config.access_token, config.access_token_secret): |
76 | + error_exit('Edit your config file!') |
77 | |
78 | def check_imports(): |
79 | - try: |
80 | - import tweepy |
81 | - except ImportError: |
82 | - error_exit('Failed to import the Tweepy library! (http://pypi.python.org/pypi/tweepy)') |
83 | + try: |
84 | + import tweepy |
85 | + except ImportError: |
86 | + error_exit('Failed to import the Tweepy library! (http://pypi.python.org/pypi/tweepy)') |
87 | |
88 | def check_privileges(): |
89 | - if check_windows(): |
90 | - if ctypes.windll.shell32.IsUserAnAdmin() != 0: |
91 | - return True |
92 | - else: |
93 | - return False |
94 | - else: |
95 | - if os.getuid() == 0 or os.geteuid() == 0: |
96 | - return True |
97 | - else: |
98 | - return False |
99 | + if check_windows(): |
100 | + return True if ctypes.windll.shell32.IsUserAnAdmin() != 0 else return False |
101 | + else: |
102 | + return True if os.getuid() == 0 or os.geteuid() == 0 else return False |
103 | |
104 | def check_version(major): |
105 | - if sys.version_info.major == major: |
106 | - return True |
107 | - else: |
108 | - return False |
109 | + return True if sys.version_info.major == major else return False |
110 | |
111 | def check_windows(): |
112 | - if os.name == 'nt': |
113 | - return True |
114 | - else: |
115 | - return False |
116 | + return True if os.name == 'nt' else return False |
117 | |
118 | def clear(): |
119 | - if check_windows(): |
120 | - os.system('cls') |
121 | - else: |
122 | - os.system('clear') |
123 | + os.system('cls') if check_windows() else os.system('clear') |
124 | |
125 | def error(msg, reason=None): |
126 | - if reason: |
127 | - print('%s | [!] - %s (%s)' % (get_time(), msg, str(reason))) |
128 | - else: |
129 | - print('%s | [!] - %s' % (get_time(), msg)) |
130 | + print(f'{get_time()} | [!] - {msg} ({str(reason)})') if reason else print(f'{get_time()} | [!] - {msg}') |
131 | |
132 | def error_exit(msg): |
133 | - raise SystemExit('%s | [!] - %s' % (get_time(), msg)) |
134 | + raise SystemExit(f'{get_time()} | [!] - {msg}') |
135 | |
136 | def get_time(): |
137 | - return time.strftime('%I:%M:%S') |
138 | + return time.strftime('%I:%M:%S') |
139 | |
140 | def get_windows(): |
141 | - if os.name == 'nt': |
142 | - return True |
143 | - else: |
144 | - return False |
145 | + return True if os.name == 'nt' else False |
146 | |
147 | def info(): |
148 | - clear() |
149 | - print(''.rjust(56, '#')) |
150 | - print('#{0}#'.format(''.center(54))) |
151 | - print('#{0}#'.format('Booster Twitter Bot'.center(54))) |
152 | - print('#{0}#'.format('Developed by acidvegas in Python 3'.center(54))) |
153 | - print('#{0}#'.format('https://acid.vegas/booster'.center(54))) |
154 | - print('#{0}#'.format(''.center(54))) |
155 | - print(''.rjust(56, '#')) |
156 | - |
157 | + clear() |
158 | + print(''.rjust(56, '#')) |
159 | + print('#{0}#'.format(''.center(54))) |
160 | + print('#{0}#'.format('Booster Twitter Bot'.center(54))) |
161 | + print('#{0}#'.format('Developed by acidvegas in Python'.center(54))) |
162 | + print('#{0}#'.format('https://acid.vegas/booster'.center(54))) |
163 | + print('#{0}#'.format(''.center(54))) |
164 | + print(''.rjust(56, '#')) |
165 | |
166 | def keep_alive(): |
167 | - try: |
168 | - while True: |
169 | - input('') |
170 | - except KeyboardInterrupt: |
171 | - sys.exit() |
172 | + try: |
173 | + while True: |
174 | + input('') |
175 | + except KeyboardInterrupt: |
176 | + sys.exit() |
177 | diff --git a/booster/functions.py b/booster/functions.py |
178 | index 956cb06..6033fa7 100644 |
179 | --- a/booster/functions.py |
180 | +++ b/booster/functions.py |
181 | @@ -7,17 +7,15 @@ import random |
182 | import urllib.request |
183 | |
184 | def get_day(): |
185 | - return datetime.datetime.today().weekday() |
186 | + return datetime.datetime.today().weekday() |
187 | |
188 | def get_source(url): |
189 | - req = urllib.request.Request(url) |
190 | - req.add_header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)') |
191 | - source = urllib.request.urlopen(req, timeout=10) |
192 | - charset = source.headers.get_content_charset() |
193 | - if charset: |
194 | - return source.read().decode(charset) |
195 | - else: |
196 | - return source.read().decode() |
197 | + req = urllib.request.Request(url) |
198 | + req.add_header('User-Agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)') |
199 | + source = urllib.request.urlopen(req, timeout=10) |
200 | + charset = source.headers.get_content_charset() |
201 | + if charset: |
202 | + return source.read().decode(charset) if charset else return source.read().decode() |
203 | |
204 | def random_int(min, max): |
205 | - return random.randint(min, max) |
206 | + return random.randint(min, max) |
207 | diff --git a/booster/twitter.py b/booster/twitter.py |
208 | index e2ba905..8ee255b 100644 |
209 | --- a/booster/twitter.py |
210 | +++ b/booster/twitter.py |
211 | @@ -13,156 +13,156 @@ import debug |
212 | import functions |
213 | |
214 | class Booster(object): |
215 | - def __init__(self): |
216 | - self.api = None |
217 | - self.me = None |
218 | - self.favorites = 0 |
219 | - self.max_favorites = config.max_favorites |
220 | - self.follows = 0 |
221 | - self.max_follows = config.max_follows |
222 | - self.messages = 0 |
223 | - self.max_messages = config.max_messages |
224 | - self.tweets = 0 |
225 | - self.max_tweets = config.max_tweets |
226 | - self.unfollows = 0 |
227 | - self.max_unfollows = config.max_unfollows |
228 | - self.send_message = config.send_message |
229 | - self.message = config.message |
230 | + def __init__(self): |
231 | + self.api = None |
232 | + self.me = None |
233 | + self.favorites = 0 |
234 | + self.max_favorites = config.max_favorites |
235 | + self.follows = 0 |
236 | + self.max_follows = config.max_follows |
237 | + self.messages = 0 |
238 | + self.max_messages = config.max_messages |
239 | + self.tweets = 0 |
240 | + self.max_tweets = config.max_tweets |
241 | + self.unfollows = 0 |
242 | + self.max_unfollows = config.max_unfollows |
243 | + self.send_message = config.send_message |
244 | + self.message = config.message |
245 | |
246 | - def run(self): |
247 | - self.login() |
248 | - threading.Thread(target=self.loop_boost).start() |
249 | - threading.Thread(target=self.loop_favorite).start() |
250 | - threading.Thread(target=self.loop_follow).start() |
251 | - threading.Thread(target=self.loop_search).start() |
252 | -# threading.Thread(target=self.loop_trend).start() |
253 | + def run(self): |
254 | + self.login() |
255 | + threading.Thread(target=self.loop_boost).start() |
256 | + threading.Thread(target=self.loop_favorite).start() |
257 | + threading.Thread(target=self.loop_follow).start() |
258 | + threading.Thread(target=self.loop_search).start() |
259 | + threading.Thread(target=self.loop_trend).start() |
260 | |
261 | - def login(self): |
262 | - try: |
263 | - auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret) |
264 | - auth.set_access_token(config.access_token, config.access_token_secret) |
265 | - self.api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) |
266 | - self.me = self.api.me() |
267 | - except tweepy.TweepError as ex: |
268 | - debug.error_exit('Failed to login to Twitter! ({0})'.format(str(ex))) |
269 | + def login(self): |
270 | + try: |
271 | + auth = tweepy.OAuthHandler(config.consumer_key, config.consumer_secret) |
272 | + auth.set_access_token(config.access_token, config.access_token_secret) |
273 | + self.api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) |
274 | + self.me = self.api.me() |
275 | + except tweepy.TweepError as ex: |
276 | + debug.error_exit('Failed to login to Twitter! ({0})'.format(str(ex))) |
277 | |
278 | - def loop_boost(self): |
279 | - while True: |
280 | - try: |
281 | - if 'boost_tweet' in locals(): self.api.destroy_status(boost_tweet.id) |
282 | - boost_tweet = self.api.update_status('RT for followers! #' + ' #'.join(config.boost_keywords)) |
283 | - self.tweets += 1 |
284 | - debug.alert('Re-posted boost tweet.') |
285 | - except tweepy.TweepError as ex: |
286 | - debug.error('Error occured in the boost loop', ex) |
287 | - finally: |
288 | - random.shuffle(config.boost_keywords) |
289 | - time.sleep(60*5) |
290 | + def loop_boost(self): |
291 | + while True: |
292 | + try: |
293 | + if 'boost_tweet' in locals(): self.api.destroy_status(boost_tweet.id) |
294 | + boost_tweet = self.api.update_status('RT for followers! #' + ' #'.join(config.boost_keywords)) |
295 | + self.tweets += 1 |
296 | + debug.alert('Re-posted boost tweet.') |
297 | + except tweepy.TweepError as ex: |
298 | + debug.error('Error occured in the boost loop', ex) |
299 | + finally: |
300 | + random.shuffle(config.boost_keywords) |
301 | + time.sleep(60*5) |
302 | |
303 | - def loop_favorite(self): |
304 | - while True: |
305 | - try: |
306 | - for tweet in tweepy.Cursor(api.home_timeline, exclude_replies=True).items(50): |
307 | - if tweet.user.screen_name != me.screen_name: |
308 | - if not tweet.favorited: |
309 | - if random.choice((True, False, False, False, False)): |
310 | - api.create_favorite(tweet.id) |
311 | - self.favorites += 1 |
312 | - debug.alert('Favorited a friends tweet!') |
313 | - time.sleep(30) |
314 | - except tweepy.TweepError as ex: |
315 | - debug.error('Error occured in the favorite loop!', ex) |
316 | - finally: |
317 | - time.sleep(60*15) |
318 | + def loop_favorite(self): |
319 | + while True: |
320 | + try: |
321 | + for tweet in tweepy.Cursor(self.api.home_timeline, exclude_replies=True).items(50): |
322 | + if tweet.user.screen_name != self.me.screen_name: |
323 | + if not tweet.favorited: |
324 | + if random.choice((True, False, False, False, False)): |
325 | + self.api.create_favorite(tweet.id) |
326 | + self.favorites += 1 |
327 | + debug.alert('Favorited a friends tweet!') |
328 | + time.sleep(30) |
329 | + except tweepy.TweepError as ex: |
330 | + debug.error('Error occured in the favorite loop!', ex) |
331 | + finally: |
332 | + time.sleep(60*15) |
333 | |
334 | - def loop_follow(self): |
335 | - while True: |
336 | - try: |
337 | - followers = api.followers_ids(me.screen_name) |
338 | - friends = api.friends_ids(me.screen_name) |
339 | - non_friends = [friend for friend in followers if friend not in friends] |
340 | - debug.action('Following back {0} supporters...'.format(len(non_friends))) |
341 | - for follower in non_friends: |
342 | - api.create_friendship(follower) |
343 | - self.follows += 1 |
344 | - debug.alert('Followed back a follower!') |
345 | - if self.follows >= self.max_follows: |
346 | - break |
347 | - if self.send_message: |
348 | - api.send_direct_message(screen_name=follower, text=self.message) |
349 | - time.sleep(30) |
350 | - except tweepy.TweepError as ex: |
351 | - debug.error('Error occured in the follow loop!', ex) |
352 | - finally: |
353 | - time.sleep(60*15) |
354 | + def loop_follow(self): |
355 | + while True: |
356 | + try: |
357 | + followers = self.api.followers_ids(self.me.screen_name) |
358 | + friends = self.api.friends_ids(self.me.screen_name) |
359 | + non_friends = [friend for friend in followers if friend not in friends] |
360 | + debug.action('Following back {0} supporters...'.format(len(non_friends))) |
361 | + for follower in non_friends: |
362 | + self.api.create_friendship(follower) |
363 | + self.follows += 1 |
364 | + debug.alert('Followed back a follower!') |
365 | + if self.follows >= self.max_follows: |
366 | + break |
367 | + if self.send_message: |
368 | + self.api.send_direct_message(screen_name=follower, text=self.message) |
369 | + time.sleep(30) |
370 | + except tweepy.TweepError as ex: |
371 | + debug.error('Error occured in the follow loop!', ex) |
372 | + finally: |
373 | + time.sleep(60*15) |
374 | |
375 | - def loop_search(self): |
376 | - while True: |
377 | - try: |
378 | - query = random.choice(config.boost_keywords) |
379 | - for item in api.search(q='#' + query, count=50, lang='en', result_type='recent'): |
380 | - if not item.user.following and not item.favorited: |
381 | - try: |
382 | - api.create_favorite(item.id) |
383 | - api.create_friendship(item.user.screen_name) |
384 | - self.favorites += 1 |
385 | - self.follows += 1 |
386 | - debug.alert('Followed a booster twitter!') |
387 | - except tweepy.TweepError as ex: |
388 | - debug.error('Unknown error occured in the search loop!', ex) |
389 | - time.sleep(30) |
390 | - except tweepy.TweepError as ex: |
391 | - debug.error('Error occured in the search loop!', ex) |
392 | - finally: |
393 | - time.sleep(60*15) |
394 | + def loop_search(self): |
395 | + while True: |
396 | + try: |
397 | + query = random.choice(config.boost_keywords) |
398 | + for item in self.api.search(q='#' + query, count=50, lang='en', result_type='recent'): |
399 | + if not item.user.following and not item.favorited: |
400 | + try: |
401 | + self.api.create_favorite(item.id) |
402 | + self.api.create_friendship(item.user.screen_name) |
403 | + self.favorites += 1 |
404 | + self.follows += 1 |
405 | + debug.alert('Followed a booster twitter!') |
406 | + except tweepy.TweepError as ex: |
407 | + debug.error('Unknown error occured in the search loop!', ex) |
408 | + time.sleep(30) |
409 | + except tweepy.TweepError as ex: |
410 | + debug.error('Error occured in the search loop!', ex) |
411 | + finally: |
412 | + time.sleep(60*15) |
413 | |
414 | - def loop_trend(self): |
415 | - while True: |
416 | - try: |
417 | - trends = self.api.trends_place(str(config.woeid)) |
418 | - hashtags = [x['name'] for x in trends[0]['trends'] if x['name'].startswith('#')] |
419 | - for trend in hashtags: |
420 | - for item in self.api.search(q=trend, count=5, lang='en', result_type='top'): |
421 | - #self.api.update_status(item.tweet) # FIX THIS PART |
422 | - time.sleep(30) |
423 | - except tweepy.TweepError as ex: |
424 | - debug.error('Error occured in the trend loop!', ex) |
425 | - finally: |
426 | - time.sleep(60*15) |
427 | + def loop_trend(self): |
428 | + while True: |
429 | + try: |
430 | + trends = self.api.trends_place(str(config.woeid)) |
431 | + hashtags = [x['name'] for x in trends[0]['trends'] if x['name'].startswith('#')] |
432 | + for trend in hashtags: |
433 | + for item in self.api.search(q=trend, count=5, lang='en', result_type='top'): |
434 | + self.api.update_status(item.tweet) |
435 | + time.sleep(30) |
436 | + except tweepy.TweepError as ex: |
437 | + debug.error('Error occured in the trend loop!', ex) |
438 | + finally: |
439 | + time.sleep(60*15) |
440 | |
441 | - def loop_unfollow(self): |
442 | - try: |
443 | - followers = self.api.followers_ids(self.me.screen_name) |
444 | - friends = self.api.friends_ids(self.me.screen_name) |
445 | - non_friends = [friend for friend in friends if friend not in followers] |
446 | - non_friends.reverse() |
447 | - debug.action('Unfollowing {0} unsupporting friends...'.format(len(non_friends))) |
448 | - for friend in non_friends: |
449 | - self.api.destroy_friendship(friend) |
450 | - self.unfollows += 1 |
451 | - debug.alert('Unfollowed an unsupporting friend!') |
452 | - if self.unfollows == self.max_unfollows: |
453 | - break |
454 | - else: |
455 | - time.sleep(60*functions.random_int(10,15)) |
456 | - except tweepy.TweepError as ex: |
457 | - debug.error('Error occured in the unfollow loop!', ex) |
458 | - finally: |
459 | - self.unfollows = 0 |
460 | + def loop_unfollow(self): |
461 | + try: |
462 | + followers = self.api.followers_ids(self.me.screen_name) |
463 | + friends = self.api.friends_ids(self.me.screen_name) |
464 | + non_friends = [friend for friend in friends if friend not in followers] |
465 | + non_friends.reverse() |
466 | + debug.action('Unfollowing {0} unsupporting friends...'.format(len(non_friends))) |
467 | + for friend in non_friends: |
468 | + self.api.destroy_friendship(friend) |
469 | + self.unfollows += 1 |
470 | + debug.alert('Unfollowed an unsupporting friend!') |
471 | + if self.unfollows == self.max_unfollows: |
472 | + break |
473 | + else: |
474 | + time.sleep(60*functions.random_int(10,15)) |
475 | + except tweepy.TweepError as ex: |
476 | + debug.error('Error occured in the unfollow loop!', ex) |
477 | + finally: |
478 | + self.unfollows = 0 |
479 | |
480 | - def ratio_check(self): |
481 | - if self.follows >= max_follows: |
482 | - time.sleep(86400) |
483 | - if me.friends_count >= 2000: |
484 | - ratio = me.friends_count + (me.followers_count/10) |
485 | - if me.friends_count >= ratio: |
486 | - debug.action('Following to follower ratio is off! Starting the unfollow loop...') |
487 | - unfollow_loop() |
488 | + def ratio_check(self): |
489 | + if self.follows >= max_follows: |
490 | + time.sleep(86400) |
491 | + if self.me.friends_count >= 2000: |
492 | + ratio = self.me.friends_count + (self.me.followers_count/10) |
493 | + if self.me.friends_count >= ratio: |
494 | + debug.action('Following to follower ratio is off! Starting the unfollow loop...') |
495 | + unfollow_loop() |
496 | |
497 | - def stats(self): |
498 | - debug.action('SceenName : ' + self.me.screen_name) |
499 | - debug.action('Registered : ' + self.me.created_at) |
500 | - debug.action('Favorites : ' + self.me.favourites_count) |
501 | - debug.action('Following : ' + self.me.friends_count) |
502 | - debug.action('Followers : ' + self.me.followers_count) |
503 | - debug.action('Tweets : ' + self.me.statuses_count) |
504 | + def stats(self): |
505 | + debug.action('SceenName : ' + self.me.screen_name) |
506 | + debug.action('Registered : ' + self.me.created_at) |
507 | + debug.action('Favorites : ' + self.me.favourites_count) |
508 | + debug.action('Following : ' + self.me.friends_count) |
509 | + debug.action('Followers : ' + self.me.followers_count) |
510 | + debug.action('Tweets : ' + self.me.statuses_count) |