jiemianNews/defs/model.py

29 lines
931 B
Python
Raw Permalink Normal View History

2022-08-02 13:14:10 +00:00
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", "")
2024-04-01 06:31:16 +00:00
self.text = f"<b>{self.title}</b>\n\n{self.summary}\n\n{self.publish_time_human} | @jiemianNew"
2022-08-02 13:14:10 +00:00
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), "")