1
0
forked from Mirrors/itch-dl

Upgrade to Python 3.10+

We can use fancier type annotations now, newer deps, more checkers.
This commit is contained in:
Ryszard Knop
2025-02-14 14:55:54 +01:00
parent d307ae8db7
commit cb08443778
8 changed files with 67 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
from datetime import datetime
from typing import TypedDict, Dict, List, Any, Tuple, Optional
from typing import TypedDict, Any
from bs4 import BeautifulSoup
@@ -9,26 +9,26 @@ class InfoboxMetadata(TypedDict, total=False):
released_at: datetime
published_at: datetime
status: str
platforms: List[str] # Windows/macOS/Linux/etc
platforms: list[str] # Windows/macOS/Linux/etc
publisher: str
author: Dict[str, str] # See impl below!
authors: Dict[str, str] # Links
genre: Dict[str, str] # Links
tools: Dict[str, str] # Links
license: Dict[str, str] # Links
asset_license: Dict[str, str] # Links
tags: Dict[str, str] # Links
author: dict[str, str] # See impl below!
authors: dict[str, str] # Links
genre: dict[str, str] # Links
tools: dict[str, str] # Links
license: dict[str, str] # Links
asset_license: dict[str, str] # Links
tags: dict[str, str] # Links
length: str
multiplayer: Dict[str, str] # Links
multiplayer: dict[str, str] # Links
player_count: str
accessibility: Dict[str, str] # Links
inputs: Dict[str, str] # Links
links: Dict[str, str] # Links
mentions: Dict[str, str] # Links
category: Dict[str, str] # Links
accessibility: dict[str, str] # Links
inputs: dict[str, str] # Links
links: dict[str, str] # Links
mentions: dict[str, str] # Links
category: dict[str, str] # Links
def parse_date_block(td: BeautifulSoup) -> Optional[datetime]:
def parse_date_block(td: BeautifulSoup) -> datetime | None:
abbr = td.find("abbr")
if not abbr or "title" not in abbr.attrs:
return None
@@ -39,17 +39,17 @@ def parse_date_block(td: BeautifulSoup) -> Optional[datetime]:
return datetime(date.year, date.month, date.day, time.hour, time.minute)
def parse_links(td: BeautifulSoup) -> Dict[str, str]:
def parse_links(td: BeautifulSoup) -> dict[str, str]:
"""Parses blocks of comma-separated <a> blocks, returns a dict
of link text -> URL it points at."""
return {link.text.strip(): link["href"] for link in td.find_all("a")}
def parse_text_from_links(td: BeautifulSoup) -> List[str]:
def parse_text_from_links(td: BeautifulSoup) -> list[str]:
return list(parse_links(td).keys())
def parse_tr(name: str, content: BeautifulSoup) -> Optional[Tuple[str, Any]]:
def parse_tr(name: str, content: BeautifulSoup) -> tuple[str, Any] | None:
if name == "Updated":
return "updated_at", parse_date_block(content)
elif name == "Release date":