aboutsummaryrefslogtreecommitdiffstats
path: root/sega/maimaidx_jp.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-04-15 00:25:29 -0700
committerPinapelz <yukais@pinapelz.com>2025-04-15 00:25:29 -0700
commit5bf27feebd8087932de138bda1a4605acc95bef4 (patch)
tree677dc1cafffaf7b9416e2307d2ba07a442662062 /sega/maimaidx_jp.py
parent91f4a6ba665ff92a759758bec5ae13528da6a3c1 (diff)
refactor sega games to follow function factory design
unlikely to be much change between each game
Diffstat (limited to 'sega/maimaidx_jp.py')
-rw-r--r--sega/maimaidx_jp.py85
1 files changed, 49 insertions, 36 deletions
diff --git a/sega/maimaidx_jp.py b/sega/maimaidx_jp.py
index 90530f0..720a618 100644
--- a/sega/maimaidx_jp.py
+++ b/sega/maimaidx_jp.py
@@ -1,46 +1,59 @@
from bs4 import BeautifulSoup
from datetime import datetime, timezone, timedelta
from urllib.parse import urljoin
-import re
+from enum import Enum
-def parse_maimaidx_jp_prism_plus_news_site(html: str):
- soup = BeautifulSoup(html, "html.parser")
- base_url = "https://info-maimai.sega.jp/"
- news_items = []
+class ParserVersion(Enum):
+ ALPHA=1
- news_boxes = soup.select(".maiPager-content .newsBox")
- for box in news_boxes:
- a_tag = box.select_one("a")
- url = urljoin(base_url, a_tag["href"]) if a_tag and a_tag.get("href") else None
+def make_maimaidx_jpn_parser(identifier: str, parser: ParserVersion):
+ def alpha_parser(html: str):
+ """
+ Confirmed on:
+ PRISM PLUS
+ """
+ soup = BeautifulSoup(html, "html.parser")
+ base_url = "https://info-maimai.sega.jp/"
+ news_items = []
- img_tag = box.select_one("img")
- image_url = urljoin(base_url, img_tag["src"]) if img_tag else None
+ news_boxes = soup.select(".maiPager-content .newsBox")
+ for box in news_boxes:
+ a_tag = box.select_one("a")
+ url = urljoin(base_url, a_tag["href"]) if a_tag and a_tag.get("href") else None
- date_tag = box.select_one(".newsDate")
- raw_date = date_tag.get_text(strip=True) if date_tag else None
+ img_tag = box.select_one("img")
+ image_url = urljoin(base_url, img_tag["src"]) if img_tag else None
- jst = timezone(timedelta(hours=9))
- try:
- dt = datetime.strptime(raw_date.split(" ")[0], "%Y.%m.%d").replace(tzinfo=jst)
- timestamp = int(dt.timestamp())
- except:
- dt = None
- timestamp = 0
+ date_tag = box.select_one(".newsDate")
+ raw_date = date_tag.get_text(strip=True) if date_tag else None
- content_tag = box.select_one(".newsLink")
- content = content_tag.get_text(strip=True) if content_tag else None
- news_items.append({
- "date": raw_date,
- "identifier": "MAIMAIDX_JPN_PRISM_PLUS",
- "type": None,
- "timestamp": timestamp,
- "headline": None,
- "content": content,
- "url": url,
- "images": [{
- "image": image_url,
- "link": url
- }] if image_url else []
- })
+ jst = timezone(timedelta(hours=9))
+ try:
+ dt = datetime.strptime(raw_date.split(" ")[0], "%Y.%m.%d").replace(tzinfo=jst)
+ timestamp = int(dt.timestamp())
+ except:
+ dt = None
+ timestamp = 0
- return news_items
+ content_tag = box.select_one(".newsLink")
+ content = content_tag.get_text(strip=True) if content_tag else None
+
+ news_items.append({
+ "date": raw_date,
+ "identifier": identifier,
+ "type": None,
+ "timestamp": timestamp,
+ "headline": None,
+ "content": content,
+ "url": url,
+ "images": [{
+ "image": image_url,
+ "link": url
+ }] if image_url else []
+ })
+
+ return news_items
+ if parser == ParserVersion.ALPHA:
+ return alpha_parser
+
+parse_maimaidx_jp_prism_plus_news_site = make_maimaidx_jpn_parser("MAIMAIDX_JPN_PRISM_PLUS", ParserVersion.ALPHA)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage