fix: 按日期统计时保留翻页状态
This commit is contained in:
+59
-12
@@ -375,6 +375,50 @@ def day_span(when: datetime) -> tuple[str, str]:
|
||||
return text, text
|
||||
|
||||
|
||||
def ajax_hidden_fields(payload: str) -> dict[str, str]:
|
||||
"""读出我的学时翻页回包里的视图状态。回包不是整页,隐藏域在末尾的分段里。"""
|
||||
fields: dict[str, str] = {}
|
||||
text = payload or ""
|
||||
index = 0
|
||||
size = len(text)
|
||||
while index < size:
|
||||
bar = text.find("|", index)
|
||||
if bar < 0:
|
||||
break
|
||||
length_text = text[index:bar]
|
||||
if not length_text.isdigit():
|
||||
index = bar + 1
|
||||
continue
|
||||
length = int(length_text)
|
||||
index = bar + 1
|
||||
bar = text.find("|", index)
|
||||
if bar < 0:
|
||||
break
|
||||
kind = text[index:bar]
|
||||
index = bar + 1
|
||||
bar = text.find("|", index)
|
||||
if bar < 0:
|
||||
break
|
||||
field_id = text[index:bar]
|
||||
index = bar + 1
|
||||
if index + length > size:
|
||||
break
|
||||
content = text[index:index + length]
|
||||
index += length
|
||||
if index < size and text[index] == "|":
|
||||
index += 1
|
||||
if kind == "hiddenField":
|
||||
fields[field_id] = content
|
||||
return fields
|
||||
|
||||
|
||||
def _carry_state(form: dict[str, str], html: str) -> dict[str, str]:
|
||||
for key, value in ajax_hidden_fields(html).items():
|
||||
if key.startswith("__"):
|
||||
form[key] = value
|
||||
return form
|
||||
|
||||
|
||||
def period_search_form(html: str, start: str, end: str) -> dict[str, str]:
|
||||
form = training_form(html)
|
||||
form["txtStartDate"] = start
|
||||
@@ -385,7 +429,7 @@ def period_search_form(html: str, start: str, end: str) -> dict[str, str]:
|
||||
form["__EVENTARGUMENT"] = ""
|
||||
form["__ASYNCPOST"] = "true"
|
||||
form["btnSearch"] = "搜索"
|
||||
return form
|
||||
return _carry_state(form, html)
|
||||
|
||||
|
||||
def period_form(html: str, argument: str, page_nav: str | None = None) -> dict[str, str]:
|
||||
@@ -396,7 +440,7 @@ def period_form(html: str, argument: str, page_nav: str | None = None) -> dict[s
|
||||
form["__ASYNCPOST"] = "true"
|
||||
if page_nav is not None:
|
||||
form["pageNav"] = page_nav
|
||||
return form
|
||||
return _carry_state(form, html)
|
||||
|
||||
|
||||
def period_has_next(html: str, page: int) -> bool:
|
||||
@@ -1396,15 +1440,6 @@ class EunivClient:
|
||||
def _rows_for_range(self, start: str | None = None, end: str | None = None) -> list[dict]:
|
||||
"""读取我的学时表格。给出日期时先按这个范围搜索,再按每页 100 条取完。"""
|
||||
html = self._open_period()
|
||||
if start:
|
||||
html = self._post_period(period_search_form(html, start, end or start))
|
||||
nav = training_form(html).get("pageNav", "")
|
||||
if not nav.endswith("|100"):
|
||||
form = period_form(html, "current", "1|0|100")
|
||||
if start:
|
||||
form["txtStartDate"] = start
|
||||
form["txtEndDate"] = end or start
|
||||
html = self._post_period(form)
|
||||
items: list[dict] = []
|
||||
seen: set[tuple] = set()
|
||||
|
||||
@@ -1419,7 +1454,19 @@ class EunivClient:
|
||||
added += 1
|
||||
return added
|
||||
|
||||
take(html)
|
||||
if start:
|
||||
html = self._post_period(period_search_form(html, start, end or start))
|
||||
take(html)
|
||||
nav = training_form(html).get("pageNav", "")
|
||||
if not nav.endswith("|100"):
|
||||
form = period_form(html, "current", "1|0|100")
|
||||
if start:
|
||||
form["txtStartDate"] = start
|
||||
form["txtEndDate"] = end or start
|
||||
widened = self._post_period(form)
|
||||
if history_rows_from_page(widened):
|
||||
html = widened
|
||||
take(html)
|
||||
limited = False
|
||||
for page in range(2, 51):
|
||||
if not period_has_next(html, page - 1):
|
||||
|
||||
Reference in New Issue
Block a user