Updating the defition of our SQLAlchemy model
This commit is contained in:
parent
15e1f837c8
commit
359b3271e4
72
scrarls.py
72
scrarls.py
@ -2,6 +2,7 @@
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import scrapy
|
||||
@ -9,24 +10,69 @@ from scrapy.crawler import CrawlerProcess
|
||||
from scrapy.spiders import CrawlSpider, Rule
|
||||
from scrapy.linkextractors import LinkExtractor
|
||||
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy import create_engine, func, select, Engine, Integer, String, Text, DateTime
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
"""Base déclarative pour SQLAlchemy 2.0."""
|
||||
pass
|
||||
|
||||
|
||||
class TvShow(Base):
|
||||
__tablename__ = 'tvshows'
|
||||
id = Column(Integer, primary_key=True)
|
||||
rlsbb_id = Column(Integer, nullable=False)
|
||||
article_title = Column(String(255), nullable=False)
|
||||
title = Column(String(255), nullable=False)
|
||||
date = Column(DateTime, nullable=False)
|
||||
summary = Column(Text, nullable=True)
|
||||
image_url = Column(String(length=255), nullable=True)
|
||||
download_url = Column(String(length=255), nullable=True)
|
||||
class TvShowDB(Base):
|
||||
"""Modèle pour le stockage des épisodes (SQLAlchemy 2.0)."""
|
||||
|
||||
__tablename__: str = "tvshows"
|
||||
|
||||
id: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True
|
||||
)
|
||||
post_id: Mapped[str] = mapped_column(
|
||||
String(length=255),
|
||||
nullable=False,
|
||||
unique=True,
|
||||
index=True
|
||||
)
|
||||
post_title: Mapped[str] = mapped_column(
|
||||
String(255),
|
||||
nullable=False
|
||||
)
|
||||
title: Mapped[str] = mapped_column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
date: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
summary: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True
|
||||
)
|
||||
image_url: Mapped[str | None] = mapped_column(
|
||||
String(255),
|
||||
nullable=True
|
||||
)
|
||||
download_url: Mapped[str | None] = mapped_column(
|
||||
String(255),
|
||||
nullable=True
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
server_default=func.datetime('now'),
|
||||
nullable=False
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
server_default=func.datetime('now'),
|
||||
onupdate=func.datetime('now'),
|
||||
nullable=False
|
||||
)
|
||||
|
||||
class TvShowItem(scrapy.Item):
|
||||
post_id: scrapy.Field = scrapy.Field()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user