This repository was archived by the owner on May 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_abit_poisk.py
More file actions
88 lines (78 loc) · 3.69 KB
/
Copy pathparse_abit_poisk.py
File metadata and controls
88 lines (78 loc) · 3.69 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
import aiohttp
from bs4 import BeautifulSoup
from config import ABIT_POISK_API_URL
from app.services.logger import log_error, log_parsing_step
async def fetch_applicant_data(name: str, tg_id: int = 0) -> list[dict]:
"""Приймає ім'я людини і повертає інформацію про цю людину з abit-poisk
Args:
name (str): ім'я абітурієнта
tg_id (int): Telegram ID користувача для логування
Returns:
list[dict]: всі його заяви і інформація про них (порожній список якщо помилка)
"""
headers = {
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
}
try:
log_parsing_step(tg_id, f"Fetching abit-poisk data for {name}")
connector = aiohttp.TCPConnector(ssl=False) # вимикаємо перевірку SSL
async with aiohttp.ClientSession(
connector=connector,
timeout=aiohttp.ClientTimeout(total=10),
headers=headers,
) as session:
async with session.post(
ABIT_POISK_API_URL,
data={"search": name},
timeout=aiohttp.ClientTimeout(total=10),
) as resp:
if resp.status != 200:
log_error(
RuntimeError(f"abit-poisk returned {resp.status}"),
f"[User {tg_id}] {name}",
)
return []
json_data = await resp.json()
html = json_data.get("html", "")
if not html:
log_parsing_step(tg_id, f"No HTML data for {name}")
return []
soup = BeautifulSoup(html, "html.parser")
rows = soup.select("table.table tbody tr")
result = []
for row in rows:
cells = row.find_all("td")
if len(cells) < 14:
continue
entry = {
"degree": cells[0].get_text(strip=True), # ОКР
"full_name": cells[1].get_text(strip=True), # ПІБ
"status": cells[2].get_text(strip=True), # Статус заяви
"ranking_number": cells[3].get_text(strip=True), # № у списку
"priority": cells[4].get_text(strip=True), # Пріоритет
"total_score": cells[6].get_text(strip=True), # Заг. бал
"education_avg": cells[7].get_text(strip=True), # СБО
"university": cells[9].get_text(strip=True), # ВНЗ
"faculty": cells[10].get_text(strip=True), # Факультет
"specialty": cells[11].get_text(strip=True), # Спец.
"quota": cells[12].get_text(strip=True), # Квота
"original_docs_submitted": cells[13].get_text(strip=True), # Оригінали
}
result.append(entry)
log_parsing_step(tg_id, f"Found {len(result)} applications for {name}")
return result
except aiohttp.ClientConnectorError as e:
log_error(
e, f"[User {tg_id}] Network error contacting abit-poisk: {str(e)[:100]}"
)
return []
except aiohttp.ClientSSLError as e:
log_error(e, f"[User {tg_id}] SSL error with abit-poisk: {str(e)[:100]}")
return []
except aiohttp.ClientError as e:
log_error(e, f"[User {tg_id}] aiohttp error: {str(e)[:100]}")
return []
except Exception as e:
log_error(e, f"[User {tg_id}] Unexpected error fetching abit data for {name}")
return []