-
Notifications
You must be signed in to change notification settings - Fork 0
/
Site_Checker_Bot.py
212 lines (178 loc) · 9.02 KB
/
Site_Checker_Bot.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
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
import telebot
from telebot import types
from telebot.types import ReplyKeyboardRemove
from AutomatedWeb import Site_Checking
bot = telebot.TeleBot("TOKEN")
language = ""
big_category = ""
medium_category = ""
small_category = ""
extra_category = ""
filter_element_one = {}
filter_element_two = {}
filter_element_three = {}
list_of_category1 = []
num = 0
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
print(message.chat.id)
print(message)
bot.send_message(message.chat.id, "Welcome to site parser!")
choose_language(message)
@bot.message_handler(commands=['lan', 'language'])
def choose_language(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
lat_lan = types.KeyboardButton("Latvian (LV)")
rus_lan = types.KeyboardButton("Russian (RU)")
markup.add(rus_lan, lat_lan)
bot.send_message(message.chat.id, "Choose language (LV or RU)?", reply_markup=markup)
@bot.message_handler(commands=['category'])
def big_category_choose(message):
if language == "LV":
latvian_list = ["Darbs un bizness", "Transports", "Nekustamie īpašumi", "Celtniecība", "Elektrotehnika",
"Drēbes, apavi", "Mājai", "Ražošana", "Bērniem", "Dzīvnieki", "Lauksaimniecība",
"Atpūta, hobiji"]
big_category_name(message, latvian_list)
elif language == "RU":
russian_list = ["Работа и бизнес", "Транспорт", "Недвижимость", "Строительство", "Электротехника",
"Одежда, обувь",
"Для дома", "Производство", "Для детей", "Животные", "Сельское хозяйство", "Отдых, увлечения"]
big_category_name(message, russian_list)
else:
bot.send_message(message.chat.id, "You didn't have chosen language")
choose_language(message)
@bot.message_handler(commands=['test'])
def big_category_name(message, list_of_category):
global list_of_category1
list_of_category1 = list_of_category
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
c1 = types.KeyboardButton(list_of_category[0])
c2 = types.KeyboardButton(list_of_category[1])
c3 = types.KeyboardButton(list_of_category[2])
c4 = types.KeyboardButton(list_of_category[3])
c5 = types.KeyboardButton(list_of_category[4])
c6 = types.KeyboardButton(list_of_category[5])
c7 = types.KeyboardButton(list_of_category[6])
c8 = types.KeyboardButton(list_of_category[7])
c9 = types.KeyboardButton(list_of_category[8])
c10 = types.KeyboardButton(list_of_category[9])
c11 = types.KeyboardButton(list_of_category[10])
c12 = types.KeyboardButton(list_of_category[1])
markup.add(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12)
bot.send_message(message.chat.id, "Now, please enter big category, where are yours element:"
"\nIf you want change language enter /lan", reply_markup=markup)
@bot.message_handler(commands=['filter', "filtering"])
def filter_menu(message):
if language == "":
bot.send_message(message.chat.id, "You didn't have chosen language")
choose_language(message)
elif big_category == "":
bot.send_message(message.chat.id, "You didn't have chosen category")
big_category_choose(message)
if language != "" and big_category != "":
bot.send_message(message.chat.id, "You can choose maximum three filtering elements "
"(or you may without filtering)"
"\nWrite text and filter you want "
"(Example: '1) TEXT : TEXT_TWO')"
"\nIf you want min and max (write 'min'-'max')")
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
b1 = types.KeyboardButton("Filter one")
b2 = types.KeyboardButton("Filter two")
b3 = types.KeyboardButton("Filter tree")
b4 = types.KeyboardButton("Without filter")
markup.add(b1, b2, b3, b4)
bot.send_message(message.chat.id, "Now, please enter big category, where are yours element:"
"\nIf you want change language enter /lan", reply_markup=markup)
print(language, big_category, medium_category, small_category, extra_category)
def filter_check(message):
global filter_element_one, filter_element_two, filter_element_three
if "one" in message.text:
return 1
elif "two" in message.text:
return 2
elif "tree" in message.text:
return 3
else:
return 4
def filter_element(message, number):
global filter_element_one, filter_element_two, filter_element_three
element_one = message.text.partition(':')[0].strip()
element_two = message.text.partition(':')[2].strip()
if "-" in element_two:
minimum = element_two.partition('-')[0].strip()
maximum = element_two.partition('-')[2].strip()
if number == 1:
filter_element_one[element_one] = minimum, maximum
elif number == 2:
filter_element_two[element_one] = minimum, maximum
elif number == 3:
filter_element_three[element_one] = minimum, maximum
else:
if number == 1:
filter_element_one[element_one] = element_two
elif number == 2:
filter_element_two[element_one] = element_two
elif number == 3:
filter_element_three[element_one] = element_two
else:
print("404")
def contruating_path(message, path):
path_list = path.split("/")
global medium_category, small_category, extra_category
if len(path_list) == 1:
medium_category = path_list[0].strip().capitalize()
elif len(path_list) == 2:
medium_category = path_list[0].strip().capitalize()
small_category = path_list[1].strip().capitalize()
elif len(path_list) == 3:
medium_category = path_list[0].strip().capitalize()
small_category = path_list[1].strip().capitalize()
extra_category = path_list[2].strip().capitalize()
else:
choose_category_1(message)
filter_menu(message)
def choose_category_1(message):
bot.send_message(message.chat.id, "Pelease, enter all cotegory to element, using slash /"
" (example Vieglie auto/Audi):")
@bot.message_handler(content_types=['text'])
def bot_message(message):
if message.chat.type == 'private':
global language, big_category, num
print(message.text)
if message.text == "Latvian (LV)" or message.text == "Russian (RU)":
language = str(message.text)[-3:-1]
bot.send_message(message.chat.id, "Ok, language will be " + message.text.lower() + ".",
reply_markup=ReplyKeyboardRemove())
big_category_choose(message)
if message.text in list_of_category1:
big_category = message.text
bot.send_message(message.chat.id,
"Big category are selected(if you want to change = /category )\n"
"Currently category: " + message.text, reply_markup=ReplyKeyboardRemove())
choose_category_1(message)
if "/" in message.text and language != "" and big_category != "":
path = message.text
contruating_path(message, path)
if ":" in message.text and num != 0:
filter_element(message, num)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
b1 = types.KeyboardButton("Filter one")
b2 = types.KeyboardButton("Filter two")
b3 = types.KeyboardButton("Filter tree")
b4 = types.KeyboardButton("Done")
markup.add(b1, b2, b3, b4)
bot.send_message(message.chat.id, "Dededed", reply_markup=markup)
print(filter_element_one, filter_element_two, filter_element_three)
if message.text in ["Filter one", "Filter two", "Filter tree", "Without filter", "Done"] and language != "" and big_category != "":
if message.text == "Done" or message.text == "Without filter":
bot.send_message(message.chat.id, "Ok", reply_markup=ReplyKeyboardRemove())
print(filter_element_one, filter_element_two, filter_element_three)
Site_Checking.main(language, big_category, medium_category, small_category, extra_category,
filter_element_one, filter_element_two, filter_element_three)
else:
bot.send_message(message.chat.id, "Now write filter (Example: TEXT:TEXT_TWO): ", reply_markup=ReplyKeyboardRemove())
num = filter_check(message)
bot.infinity_polling()
# Min-max
# Fix : in filters
# Stop function