This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.py
163 lines (138 loc) · 5.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Standard libraries
import logging
import random
import sys
import time
from datetime import datetime, timedelta
# third party libraries
import tweepy
import yaml
# Local libraries
from BotTwitter.bypass_antibot import BypassAntiBot
from BotTwitter.helper import Helper
from BotTwitter.manage_follow import ManageFollow, create_tables_follow
from BotTwitter.manage_rss import create_table_rss
from BotTwitter.retweet_giveaway import RetweetGiveaway
# Configuration
VERSION = 3.1
CONFIGURATION_FILE = "configuration.yml"
Helper = Helper()
# Load all configuration variables
with open(CONFIGURATION_FILE, 'r', encoding="utf8") as stream:
out = yaml.load(stream, Loader=yaml.FullLoader)
words_to_search = out['words_to_search']
nb_days_rollback = out['nb_days_rollback']
accounts_to_tag = out['accounts_to_tag']
sentence_for_tag = out['sentence_for_tag']
hashtag_to_blacklist = [x.upper() for x in out['hashtag_to_blacklist']]
giveaway_to_blacklist = [x.upper() for x in out['giveaway_to_blacklist']]
accounts_to_blacklist = [w.replace('@', '') for w in out['accounts_to_blacklist']]
list_account = out['accounts']
bypass_antibot = out['bypass_antibot']
like_giveaway = out['like_giveaway']
comment_with_hashtag = out['comment_with_hashtag']
max_giveaway = out['max_giveaway']
logging_level = out['logging_level']
flux_rss = out['flux_rss']
nb_account_to_tag = out['nb_account_to_tag']
# Configuration of the logging library
Helper.logging_configuration(logging_level)
# Create a table to store rss links if it does not exist.
create_table_rss()
# Main loop
while True:
list_name = []
for account in out['accounts']:
for account_name, list_auth in account.items():
try:
# Extract API & ACCESS credentials
api_key, api_secret, access_token, access_secret = list_auth
api, user = Helper.get_user(api_key, api_secret, access_token, access_secret)
create_tables_follow(user)
list_name.append("@" + user.screen_name)
logging.info("Configuration completed for the account : %s", user.screen_name)
except Exception as e:
logging.error("Error with account : %s", account_name)
logging.error(e)
continue
logging.info("-" * 40)
# Add Accounts to Tag
if accounts_to_tag:
list_name += accounts_to_tag
# We don't want a duplicate
list_name = list(set(list_name))
connection = 0
# Looking for an account to find giveaway
for account in out['accounts']:
for account_name, list_auth in account.items():
try:
# If an account is available, we break the loop
if connection == 1:
break
api_key, api_secret, access_token, access_secret = list_auth
api, user = Helper.get_user(api_key, api_secret, access_token, access_secret)
connection = 1
except:
continue
# If no account is available
if connection == 0:
logging.error("No account available!")
sys.exit()
# We retrieve a list of giveaway
else:
rtgiveaway = RetweetGiveaway(api, user)
giveaway_list = rtgiveaway.check_retweet(words_to_search,
accounts_to_blacklist,
hashtag_to_blacklist,
giveaway_to_blacklist,
comment_with_hashtag,
max_giveaway,
nb_days_rollback)
for account in out['accounts']:
for account_name, list_auth in account.items():
try:
# Thread here
# Extract API & ACCESS credentials
api_key, api_secret, access_token, access_secret = list_auth
# Authenticate Key to use Twitter API
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
user = api.verify_credentials()
logging.info("-" * 40)
logging.info("Launching the bot on : @%s", user.screen_name)
managefollow = ManageFollow(user, api)
managefollow.unfollow()
rtgiveaway = RetweetGiveaway(api, user)
rtgiveaway.manage_giveaway(giveaway_list, sentence_for_tag,
list_name, hashtag_to_blacklist,
managefollow, like_giveaway,
nb_account_to_tag)
# If the antibot bypass feature is activated
if bypass_antibot:
bypass = BypassAntiBot(api, flux_rss)
bypass.bypass()
logging.info("Sleeping for 30s...")
time.sleep(30)
except KeyboardInterrupt:
Helper.ask_to_exit()
except tweepy.TweepyException as error:
if error.api_codes == 326 or error.api_code == 32:
logging.error("Connection error : %s", account_name)
continue
else:
continue
try:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
logging.info("Current time : %s", current_time)
# Sleep if it's night time
if 22 < now.hour or now.hour < 2:
waiting_time = 7 * 3600
else:
waiting_time = random.randrange(4000, 6000)
logging.info("Waiting time before restarting bots : " + str(timedelta(seconds=waiting_time)))
logging.info("-" * 40)
time.sleep(waiting_time)
except KeyboardInterrupt:
Helper.ask_to_exit()