-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
281 lines (250 loc) · 13.5 KB
/
run.py
File metadata and controls
281 lines (250 loc) · 13.5 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import modules.rsa_checker.rsa_cheker_bot_w_site as rsa_cheker_bot
from modules.rsa_checker.rsa_cheker_bot_w_site import StopFind
from loguru import logger
import time
from datetime import datetime, timedelta
from contextlib import suppress
from modules.other_methods import check_ip
import sys
import random
from modules.json_table import JsonTable
from request_reg_ugsk.reg_acc import RegAcc as RegAccUGSK, AccAlreadyReg
from request_reg_ugsk.create_osago import CreateInsurance as CreateInsuranceUGSK, AuthErrorUGSK, CreateErrorUGSK
from request_reg_21.reg_acc import RegAcc as RegAcc21
from request_reg_21.create_osago import CreateInsurance as CreateInsurance21, AuthError21, CreateError21
from request_reg_arm.reg_acc import RegAcc as RegAccArm
from request_reg_arm.create_osago import CreateInsurance as CreateInsuranceArm, AuthErrorArm, CreateErrorArm
from request_reg_alfa.create_osago import CreateInsurance as CreateInsuranceAlfa, CreateErrorAlfa
from requests_reg_vsk.create_osago import CreateInsurance as CreateInsuranceVsk, CreateErrorVsk
sys.stdout.flush()
def check_start():
""" Проверка необходимости запуска бота """
while True:
json_table = JsonTable()
data = json_table.data
type = json_table.type
print({"data": data, "type": type})
if data != None and type == "hook":
return json_table, type
elif data != None and type == "osago_ugsk":
return json_table, type
elif data != None and type =="osago_21":
return json_table, type
elif data != None and type =="osago_arm":
return json_table, type
elif data != None and type =="osago_alfa":
return json_table, type
elif data != None and type =="osago_vsk":
return json_table, type
else:
time.sleep(random.randrange(5, 50) / 10)
@logger.catch
def start():
while True:
try:
json_table, type = check_start()
if type == "hook":
start_hook(json_table)
elif type == "osago_ugsk":
start_ugsk(json_table)
elif type == "osago_21":
start_21(json_table)
elif type == "osago_arm":
start_arm(json_table)
elif type == "osago_alfa":
start_alfa(json_table)
elif type == "osago_vsk":
start_vsk(json_table)
except Exception as err:
with suppress(Exception):
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Критическая ошибка: {err}')
def start_hook(json_table):
hook_data = json_table.data
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
try:
rsa_cheker_bot.start_find(input_url=hook_data.input_url, json_table=json_table)
except StopFind:
pass
def start_ugsk(json_table):
# ----------------------------------------------------Регистрация---------------------------------------------------
client_data = json_table.data
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
if client_data.login_osk != "":
print("Аккаунт уже зарегистрирован")
else:
try:
reg_acc = RegAccUGSK()
reg_acc.run(reg_data=client_data, json_table=json_table)
except AccAlreadyReg:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка: аккаунт уже зарегистрирован')
logger.exception("RegFailed")
return
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при регистрации')
logger.exception("RegFailed")
return
# --------------------------------------------------Создание ОСАГО--------------------------------------------------
if client_data.login_osk == "":
return
try:
create_insurance = CreateInsuranceUGSK(json_table=json_table)
create_insurance.auth()
url_rca = create_insurance.create()
rsa_cheker_bot.start_find(input_url=url_rca, json_table=json_table, telephone=create_insurance.telephone)
create_insurance.rca_create_dog(url_rca=url_rca)
json_table.stop_bot()
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Завершено')
except AuthErrorUGSK:
logger.exception("AuthErrorUGSK")
except CreateErrorUGSK:
logger.exception("CreateErrorUGSK")
except StopFind:
print("Бот остановлен")
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот остановлен')
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
with suppress(Exception):
create_insurance.telephone.end_number()
def start_21(json_table):
# ----------------------------------------------------Регистрация---------------------------------------------------
client_data = json_table.data
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
if client_data.login_osk != "":
print("Аккаунт уже зарегистрирован")
else:
try:
reg_acc = RegAcc21()
reg_acc.run(reg_data=client_data, json_table=json_table)
except AccAlreadyReg:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка: аккаунт уже зарегистрирован')
logger.exception("RegFailed")
return
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при регистрации')
logger.exception("RegFailed")
return
# --------------------------------------------------Создание ОСАГО--------------------------------------------------
if client_data.login_osk == "":
return
try:
create_insurance = CreateInsurance21(json_table=json_table)
create_insurance.auth()
url_rca = create_insurance.create()
rsa_cheker_bot.start_find(input_url=url_rca, json_table=json_table, telephone=create_insurance.telephone)
create_insurance.rca_create_dog(url_rca=url_rca)
json_table.stop_bot()
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Завершено')
except AuthError21:
logger.exception("AuthErrorUGSK")
except CreateError21:
logger.exception("CreateErrorUGSK")
except StopFind:
print("Бот остановлен")
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот остановлен')
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
with suppress(Exception):
create_insurance.telephone.end_number()
def start_arm(json_table):
# ----------------------------------------------------Регистрация---------------------------------------------------
client_data = json_table.data
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
if client_data.login_osk != "" and \
client_data.telephone != "" and \
(
(client_data.telephone_service == 'onlinesim' and (datetime.now() - datetime.strptime(client_data.reg_date_telephone, "%d.%m %H:%M %Y")) < timedelta(minutes=30)) or
((datetime.now() - datetime.strptime(client_data.reg_date_telephone, "%d.%m %H:%M %Y")) < timedelta(minutes=50))
):
print("Аккаунт уже зарегистрирован")
else:
try:
reg_acc = RegAccArm()
telephone = reg_acc.run(reg_data=client_data, json_table=json_table)[2]
reg_date = datetime.now()
tel_number = telephone.tel[1:]
json_table.set_value('reg_date_telephone', telephone.active_client.date.strftime("%d.%m %H:%M %Y"))
json_table.set_value('telephone', tel_number)
json_table.set_value('id_num_telephone', telephone.active_client.id_num)
json_table.set_value('telephone_service', telephone.active_client.name)
except AccAlreadyReg:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка: аккаунт уже зарегистрирован')
logger.exception("RegFailed")
return
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при регистрации')
logger.exception("RegFailed")
return
# --------------------------------------------------Создание ОСАГО--------------------------------------------------
while json_table.active and (
(client_data.telephone_service == 'onlinesim' and (datetime.now() - datetime.strptime(client_data.reg_date_telephone, "%d.%m %H:%M %Y")) < timedelta(minutes=30)) or
((datetime.now() - datetime.strptime(client_data.reg_date_telephone, "%d.%m %H:%M %Y")) < timedelta(minutes=50))
):
try:
create_insurance = CreateInsuranceArm(json_table=json_table)
create_insurance.auth()
url_rca = create_insurance.create()
rsa_cheker_bot.start_find(input_url=url_rca, json_table=json_table, telephone=create_insurance.telephone)
create_insurance.rca_create_dog(url_rca=url_rca)
json_table.stop_bot()
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Завершено')
except AuthErrorArm:
logger.exception("AuthErrorUGSK")
except CreateErrorArm:
logger.exception("CreateErrorUGSK")
except StopFind:
print("Бот остановлен")
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот остановлен')
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
def start_alfa(json_table):
client_data = json_table.data
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
# --------------------------------------------------Создание ОСАГО--------------------------------------------------
while json_table.active:
try:
create_insurance = CreateInsuranceAlfa(json_table=json_table)
create_insurance.auth()
create_insurance.create()
json_table.stop_bot()
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Завершено')
except CreateErrorAlfa:
logger.exception("CreateErrorAlfa")
except StopFind:
print("Бот остановлен")
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот остановлен')
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
def start_vsk(json_table):
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот приступил к выполнению')
# --------------------------------------------------Создание ОСАГО--------------------------------------------------
try:
create_insurance = CreateInsuranceVsk(json_table=json_table)
create_insurance.auth()
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
with suppress(Exception):
create_insurance.driver.quit()
return
while json_table.active:
try:
url_rca = create_insurance.create()
json_table.stop_bot()
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Завершено')
except CreateErrorVsk:
logger.exception("CreateErrorVSK")
except StopFind:
print("Бот остановлен")
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Бот остановлен')
except Exception:
json_table.set_value("status_bot", f'{datetime.now().strftime("%d.%m %H:%M")} Ошибка при создании ОСАГО')
logger.exception("CreateInsuranceFailed")
with suppress(Exception):
create_insurance.driver.quit()
if __name__ == "__main__":
logger.add("debug.log", format="{time} {level} {message}", level="DEBUG", rotation="10 MB")
start()