7455d7e426
130 issues auto-fixed (import ordering, UP045/UP006 type annotations), 33 issues manually fixed (E712/E501/E402/E722 + N818 rename + per-file wechat ignore for N8xx naming conventions). All 33 tests pass.
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
import hashlib
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, Integer, String, Text, func
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class Announcement(Base):
|
|
__tablename__ = "announcements"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
publish_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
purchase_name: Mapped[str] = mapped_column(String(200), default="")
|
|
content_url: Mapped[str] = mapped_column(Text, default="")
|
|
source_code: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
source_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
announcement_type: Mapped[str] = mapped_column(String(50), default="purchase")
|
|
content_hash: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
|
|
crawl_mode: Mapped[str] = mapped_column(String(20), default="auto")
|
|
is_new: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
is_sent: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
keyword_matched: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) # noqa: E501
|
|
|
|
@staticmethod
|
|
def generate_hash(title: str, publish_date: str, purchase_name: str,
|
|
content_url: str, source_code: str) -> str:
|
|
content = f"{title}|{publish_date}|{purchase_name}|{content_url}|{source_code}"
|
|
return hashlib.sha256(content.encode("utf-8")).hexdigest()
|
|
|
|
@staticmethod
|
|
def source_map() -> dict:
|
|
import json
|
|
|
|
from app.config import settings
|
|
return json.loads(settings.announcement_sources)
|