gettake.models

Models for gettake.

 1"""Models for gettake."""
 2
 3from __future__ import annotations
 4
 5from dataclasses import dataclass
 6from typing import TYPE_CHECKING, Literal, TypedDict
 7
 8if TYPE_CHECKING:
 9    from pathlib import Path
10    from urllib.parse import ParseResult
11
12
13@dataclass
14class Option:
15    """CLI Options for gettake."""
16
17    url: ParseResult
18    save_dir: Path
19    overwrite: bool
20    quiet: bool
21
22    def get_file_url(self, chapter: str) -> str:
23        """Get file url.
24
25        Args:
26            chapter (str): chapter name.
27
28        Returns:
29                str: file url.
30        """
31        file_url = self.url._replace(
32            path=f"/_files/{self.get_slug()}/{chapter}/data",
33        )
34        return file_url.geturl()
35
36    def get_slug(self) -> str:
37        """Get slug from url.
38
39        Returns:
40            str: slug.
41        """
42        return self.url.path.rstrip("/").split("/")[-1]
43
44
45class ImageInfo(TypedDict):
46    src: str
47    width: int
48    height: int
49
50
51class Resources(TypedDict):
52    i: ImageInfo
53
54
55class View(TypedDict):
56    width: int
57    height: int
58    coords: list[str]
59
60
61PositionOfImage = TypedDict(
62    "PositionOfImage",
63    {
64        "ptimg-version": Literal[1],
65        "resources": Resources,
66        "views": list[View],
67    },
68)
69
70
71__all__ = ("Option", "PositionOfImage")
@dataclass
class Option:
14@dataclass
15class Option:
16    """CLI Options for gettake."""
17
18    url: ParseResult
19    save_dir: Path
20    overwrite: bool
21    quiet: bool
22
23    def get_file_url(self, chapter: str) -> str:
24        """Get file url.
25
26        Args:
27            chapter (str): chapter name.
28
29        Returns:
30                str: file url.
31        """
32        file_url = self.url._replace(
33            path=f"/_files/{self.get_slug()}/{chapter}/data",
34        )
35        return file_url.geturl()
36
37    def get_slug(self) -> str:
38        """Get slug from url.
39
40        Returns:
41            str: slug.
42        """
43        return self.url.path.rstrip("/").split("/")[-1]

CLI Options for gettake.

Option( url: urllib.parse.ParseResult, save_dir: pathlib.Path, overwrite: bool, quiet: bool)
url: urllib.parse.ParseResult
save_dir: pathlib.Path
overwrite: bool
quiet: bool
def get_file_url(self, chapter: str) -> str:
23    def get_file_url(self, chapter: str) -> str:
24        """Get file url.
25
26        Args:
27            chapter (str): chapter name.
28
29        Returns:
30                str: file url.
31        """
32        file_url = self.url._replace(
33            path=f"/_files/{self.get_slug()}/{chapter}/data",
34        )
35        return file_url.geturl()

Get file url.

Arguments:
  • chapter (str): chapter name.
Returns:

str: file url.

def get_slug(self) -> str:
37    def get_slug(self) -> str:
38        """Get slug from url.
39
40        Returns:
41            str: slug.
42        """
43        return self.url.path.rstrip("/").split("/")[-1]

Get slug from url.

Returns:

str: slug.

class PositionOfImage(typing.TypedDict):
ptimg-version: Literal[1]
resources: gettake.models.Resources
views: list[gettake.models.View]