aboutsummaryrefslogtreecommitdiffstats
path: root/community/museca_plus.py
blob: b84ded59c618cc2713ac602615b6f0c7f6eff0c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from bs4 import BeautifulSoup
from datetime import datetime
from urllib.parse import urljoin
import time
import re

def parse_museca_plus_news_site(html: str) -> list:
    soup = BeautifulSoup(html, "html.parser")
    news_posts = []
    base_url = "https://museca.plus/"
    for p in soup.select("div.subcontainer.center.text > p"):
        text = p.get_text(strip=True, separator=' ')
        date_match = re.search(r'(\d{4}-\d{2}-\d{2})', text)
        if not date_match:
            continue
        date_str = date_match.group(1)
        try:
            dt = datetime.strptime(date_str, "%Y-%m-%d")
            timestamp = int(time.mktime(dt.timetuple()))
        except ValueError:
            continue
        images = []
        for img in p.find_all("img"):
            img_url = urljoin(base_url, img.get("src"))
            images.append({"image": img_url, "link": None})

        content = p.get_text(separator=' ', strip=True)

        news_posts.append({
            'date': date_str,
            'identifier': 'MUSECA_PLUS',
            'type': None,
            'timestamp': timestamp,
            'headline': None,
            'content': content,
            'url': None,
            'images': images,
            'is_ai_summary': False
        })

    return news_posts
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage