Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
59 lines (48 loc) · 1.59 KB
/
Copy pathmodels.py
File metadata and controls
59 lines (48 loc) · 1.59 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
"""
models.py
---------
Plain data containers shared by the scraper, the PDF builder and the UI.
Kept dependency-free (no Qt, no requests) so they can be reused/tested in
isolation and by future source plugins.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum, auto
class DownloadState(Enum):
PENDING = auto()
FETCHING = auto()
RENDERING = auto()
DONE = auto()
SKIPPED = auto() # already downloaded
FAILED = auto()
@dataclass
class Article:
title: str
url: str
author: str = ""
html_body: str = "" # sanitised inner HTML of the article body
image_urls: list[str] = field(default_factory=list)
@dataclass
class Issue:
"""One issue (期) of the periodical."""
source_id: str # which SourcePlugin produced this
year: int
issue_no: int # 期号, e.g. 13
title: str # e.g. "2026年第13期"
toc_url: str # the issue's 目录 page
publish_dt: datetime | None # exact publish date/time if the site provides one
cover_image_url: str = ""
articles: list[Article] = field(default_factory=list)
state: DownloadState = DownloadState.PENDING
progress: float = 0.0 # 0..1, used by the UI progress bar
error: str = ""
output_path: str = ""
@property
def display_date(self) -> str:
if self.publish_dt:
return self.publish_dt.strftime("%Y-%m-%d")
return ""
@property
def sort_key(self):
return (self.year, self.issue_no)