-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
57 lines (52 loc) · 1.81 KB
/
parse.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
import telebot
import os, pickle
import requests
import bs4
from urls import *
data = {
}
def dump():
#os.remove("users.pkl")
with open('users.pkl', 'wb') as f:
pickle.dump(data, f)
for i in range(len(contests)):
if contests[i] not in data:
data[contests[i]] = {}
# bot.send_message(my_id, "Новый контест - " + contests[i])
for i in range(len(contests)):
#print(data)
#if (contests)
r = requests.get(urls[i])
r.encoding = 'utf-8'
b = bs4.BeautifulSoup(r.text, features='lxml')
table = b.find_all('table')[1]
tasks = table.find_all('tr')
for row in tasks[1:len(tasks)-3]:
res = []
row = row.find_all('td')
name = row[1].get_text()
if (name not in data[contests[i]]):
data[contests[i]][name] = ['0']*(len(row) - 4)
# bot.send_message(my_id, contests[i] + "\nНовый юзер - " + name)
# print(data)
for cell in row[2:len(row) - 2]:
c = cell.get_text()
if (c[0] == '+'):
res.append(c)
else:
if ('cell_attr_pr' in cell['class']):
res.append('?' + c[1:])
elif c[0] == '-':
res.append(c)
else:
res.append('0')
resp = ""
# print(data[contests[i]][name], len(res))
for j in range(len(res)):
if (data[contests[i]][name][j] != res[j]):
resp += str(chr(ord('A') + j)) + ". " + data[contests[i]][name][j] + " -----> " + res[j] + "\n"
data[contests[i]][name][j] = res[j]
#if (len(resp) > 0):
# bot.send_message(my_id, contests[i] + " " + name + "\n" + resp)
dump()
#bot.send_message(my_id, "Больше обновлений нет", reply_markup=kb)