fix(edu_master): satisfy ruff in schedule scraper
- rename ambiguous loop var, merge nested if (E741, SIM102) - use tempfile.gettempdir() for debug dump (S108) - drop unused total_lessons assignment (F841)
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@@ -545,7 +546,7 @@ def _parse_schedule_cell(cell_html: str) -> list:
|
||||
text = text.strip()
|
||||
if not text:
|
||||
continue
|
||||
lines = [l.strip() for l in text.split('\n') if l.strip()]
|
||||
lines = [ln.strip() for ln in text.split('\n') if ln.strip()]
|
||||
if not lines:
|
||||
continue
|
||||
subject = lines[0] if lines else ''
|
||||
@@ -599,8 +600,9 @@ def _parse_schedule_html(table_html: str) -> dict:
|
||||
continue
|
||||
|
||||
first_cell_text = re.sub(r'<[^>]+>', '', cells[0]).strip()
|
||||
if not re.match(r'^\d+\.', first_cell_text):
|
||||
if 'Позакласне' in first_cell_text or re.search(r'colspan\s*=\s*"?(\d+)"?', row):
|
||||
if not re.match(r'^\d+\.', first_cell_text) and (
|
||||
'Позакласне' in first_cell_text or re.search(r'colspan\s*=\s*"?(\d+)"?', row)
|
||||
):
|
||||
continue
|
||||
|
||||
lesson_num_match = re.match(r'^(\d+)\.', first_cell_text)
|
||||
@@ -647,11 +649,11 @@ async def fetch_schedule_data(phpsessid: str) -> dict | None:
|
||||
logger.error('table.schedule-table not found in DOM')
|
||||
return None
|
||||
|
||||
with contextlib.suppress(Exception), open('/tmp/schedule_debug.html', 'w', encoding='utf-8') as f:
|
||||
debug_path = os.path.join(tempfile.gettempdir(), 'schedule_debug.html')
|
||||
with contextlib.suppress(Exception), open(debug_path, 'w', encoding='utf-8') as f:
|
||||
f.write(table_html)
|
||||
|
||||
data = _parse_schedule_html(table_html)
|
||||
total_lessons = sum(len(entry['classes'].get(c, [])) for day in data['weekdays'].values() for entry in day for c in data['classes'])
|
||||
logger.info(f'Schedule parsed: {len(data["weekdays"])} days, classes={data["classes"]}')
|
||||
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user