Fix socials timestamp #50
@@ -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:
|
||||
|
||||
@@ -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__()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user