This commit is contained in:
15
database/tnews/crud.py
Normal file
15
database/tnews/crud.py
Normal file
@ -0,0 +1,15 @@
|
||||
from database.tnews.model import TNews
|
||||
|
||||
|
||||
def get_news_unprocessed(db):
|
||||
return db.query(TNews).filter(
|
||||
TNews.is_usage == False,
|
||||
TNews.content != None,
|
||||
TNews.content != 'not found element'
|
||||
).all()
|
||||
|
||||
def set_news_usage(db, news_list : list[TNews]):
|
||||
for news in news_list:
|
||||
news.is_usage = True
|
||||
db.commit()
|
||||
|
||||
25
database/tnews/model.py
Normal file
25
database/tnews/model.py
Normal file
@ -0,0 +1,25 @@
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Column, String, Boolean, DateTime, BigInteger, text, INT
|
||||
from database.database import Base
|
||||
|
||||
@dataclass
|
||||
class TNews(Base):
|
||||
__tablename__ = 't_news'
|
||||
|
||||
id: int = Column(BigInteger, primary_key=True, autoincrement=True, comment='编号')
|
||||
title: Optional[str] = Column(String, nullable=True, comment='标题')
|
||||
summary: Optional[str] = Column(String, nullable=True, comment='摘要')
|
||||
url: Optional[str] = Column(String, nullable=True, comment='链接')
|
||||
content: Optional[str] = Column(String, nullable=True, comment='内容/正文')
|
||||
occurrence_date: Optional[datetime] = Column(DateTime(timezone=True), nullable=True, comment='发布日期')
|
||||
source: Optional[str] = Column(String, nullable=True, comment='来源')
|
||||
primary_category: str = Column(String, nullable=True, comment='一级类别')
|
||||
secondary_category: str = Column(String, nullable=True, comment='二级类别')
|
||||
tertiary_category: str = Column(String, nullable=True, comment='三级类别')
|
||||
label: str = Column(String, nullable=True, comment='标签')
|
||||
lang: str = Column(String, nullable=False, default='zh', comment='语言')
|
||||
is_usage: bool = Column(Boolean, nullable=False, default=False, server_default=text('false'), comment='是否已用')
|
||||
create_time: datetime = Column(DateTime(timezone=True), nullable=False, server_default=text('now()'), comment='创建日期')
|
||||
Reference in New Issue
Block a user