import time from typing import List from defs.format_time import strf_time class New: id: str publish_time: int publish_time_human: str title: str summary: str img_urls: List[str] img_url: str def __init__(self, **data): self.id = data.get("id", "") self.url = f"https://www.jiemian.com/article/{self.id}.html" try: self.publish_time = int(data.get("publishtime", time.time())) except ValueError: self.publish_time = int(time.time()) self.publish_time_human = strf_time(self.publish_time) self.title = data.get("title", "") self.summary = data.get("summary", "") self.text = f"{self.title}\n\n{self.summary}\n\n{self.publish_time_human} | @jiemianNews" self.img_urls = [img.get("thumb", "") for img in data.get("img_urls", [])] self.img_url = next((i for i in self.img_urls if i), "")