From bd19c1491a56572f6c133f2da552600974b25a4e Mon Sep 17 00:00:00 2001 From: Berack96 Date: Wed, 22 Oct 2025 10:00:22 +0200 Subject: [PATCH] fix problems with socials --- src/app/api/core/social.py | 4 ++-- src/app/api/social/chan.py | 11 ++++++++--- src/app/api/social/reddit.py | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/api/core/social.py b/src/app/api/core/social.py index fe4d5bf..ca921a0 100644 --- a/src/app/api/core/social.py +++ b/src/app/api/core/social.py @@ -22,12 +22,12 @@ class SocialComment(BaseModel): """ Represents a comment on a social media post. """ - time: str = "" + timestamp: str = "" description: str = "" def set_timestamp(self, timestamp_ms: int | None = None, timestamp_s: int | None = None) -> None: """ Use the unified_timestamp function to set the time.""" - self.time = unified_timestamp(timestamp_ms, timestamp_s) + self.timestamp = unified_timestamp(timestamp_ms, timestamp_s) class SocialWrapper: diff --git a/src/app/api/social/chan.py b/src/app/api/social/chan.py index a39e517..0f3d767 100644 --- a/src/app/api/social/chan.py +++ b/src/app/api/social/chan.py @@ -1,15 +1,20 @@ -''' -Usiamo le API di 4chan per ottenere un catalogo di threads dalla board /biz/ -''' import re import html import requests +import warnings from bs4 import BeautifulSoup from datetime import datetime from app.api.core.social import * +# Ignora i warning di BeautifulSoup quando incontra HTML malformato o un link, mentre si aspetta un HTML completo +warnings.filterwarnings("ignore") + class ChanWrapper(SocialWrapper): + """ + Wrapper per l'API di 4chan, in particolare per la board /biz/ (Business & Finance) + Fonte API: https://a.4cdn.org/biz/catalog.json + """ def __init__(self): super().__init__() diff --git a/src/app/api/social/reddit.py b/src/app/api/social/reddit.py index 201166c..306e49e 100644 --- a/src/app/api/social/reddit.py +++ b/src/app/api/social/reddit.py @@ -23,13 +23,13 @@ SUBREDDITS = [ def extract_post(post: Submission) -> SocialPost: social = SocialPost() - social.set_timestamp(timestamp_ms=post.created) + social.set_timestamp(timestamp_s=post.created) social.title = post.title social.description = post.selftext for top_comment in post.comments: comment = SocialComment() - comment.set_timestamp(timestamp_ms=top_comment.created) + comment.set_timestamp(timestamp_s=top_comment.created) comment.description = top_comment.body social.comments.append(comment)