Add Reddit monitoring bot — backend, frontend, and Docker config
Python/FastAPI backend with PostgreSQL for collecting Reddit data via public .json endpoints. React/Vite dashboard for analytics. Docker Compose setup with API and worker services connecting to shared PostgreSQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
42
backend/models/post.py
Normal file
42
backend/models/post.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import String, Boolean, Integer, Float, DateTime, ForeignKey, Index
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from backend.models.base import Base
|
||||
|
||||
|
||||
class Post(Base):
|
||||
__tablename__ = "posts"
|
||||
__table_args__ = (
|
||||
Index("ix_posts_subreddit_created", "subreddit_id", "created_utc"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
reddit_id: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
||||
subreddit_id: Mapped[int] = mapped_column(ForeignKey("monitored_subreddits.id"), index=True)
|
||||
author_id: Mapped[int | None] = mapped_column(ForeignKey("authors.id"), index=True)
|
||||
title: Mapped[str] = mapped_column(nullable=False)
|
||||
selftext: Mapped[str | None] = mapped_column()
|
||||
url: Mapped[str | None] = mapped_column()
|
||||
permalink: Mapped[str | None] = mapped_column()
|
||||
flair: Mapped[str | None] = mapped_column(String(255))
|
||||
score: Mapped[int] = mapped_column(Integer, default=0, index=True)
|
||||
upvote_ratio: Mapped[float | None] = mapped_column(Float)
|
||||
num_comments: Mapped[int] = mapped_column(Integer, default=0)
|
||||
is_self: Mapped[bool | None] = mapped_column(Boolean)
|
||||
over_18: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
hot_rank: Mapped[int | None] = mapped_column(Integer)
|
||||
created_utc: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
collected_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
onupdate=lambda: datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
subreddit: Mapped["MonitoredSubreddit"] = relationship(back_populates="posts") # noqa: F821
|
||||
author: Mapped["Author | None"] = relationship(back_populates="posts") # noqa: F821
|
||||
comments: Mapped[list["Comment"]] = relationship(back_populates="post") # noqa: F821
|
||||
metric_snapshots: Mapped[list["MetricSnapshot"]] = relationship(back_populates="post") # noqa: F821
|
||||
Reference in New Issue
Block a user