aboutsummaryrefslogtreecommitdiffstats
path: root/sega/maimaidx_intl.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_intl.py
parent91f4a6ba665ff92a759758bec5ae13528da6a3c1 (diff)
refactor sega games to follow function factory design
unlikely to be much change between each game
Diffstat (limited to 'sega/maimaidx_intl.py')
-rw-r--r--sega/maimaidx_intl.py69
1 files changed, 40 insertions, 29 deletions
diff --git a/sega/maimaidx_intl.py b/sega/maimaidx_intl.py
index 57e7cfb..1671d9f 100644
--- a/sega/maimaidx_intl.py
+++ b/sega/maimaidx_intl.py
@@ -1,36 +1,47 @@
from bs4 import BeautifulSoup
from datetime import datetime, timezone, timedelta
-import time
+from enum import Enum
-def parse_maimaidx_intl_prism_news_site(html: str):
- soup = BeautifulSoup(html, "html.parser")
- items = soup.select(".dl--pop__item")
+class ParserVersion(Enum):
+ ALPHA=1
- entries = []
- for item in items:
- date_text = item.select_one(".dl--pop__head").text.strip().replace(" UP", "")
- dt = datetime.strptime(date_text, "%Y.%m.%d").replace(tzinfo=timezone(timedelta(hours=9)))
- timestamp = int(dt.timestamp())
+def make_maimaidx_intl_parser(identifier: str, parser: ParserVersion):
+ def alpha_parser(html: str):
+ """
+ Confirmed on:
+ PRISM
+ """
+ soup = BeautifulSoup(html, "html.parser")
+ items = soup.select(".dl--pop__item")
- img_tag = item.select_one("a.dl--pop__thumb img")
- image_url = img_tag["srcset"] if img_tag else None
- full_image_url = image_url.replace("../", "https://maimai.sega.com/") if image_url else None
+ entries = []
+ for item in items:
+ date_text = item.select_one(".dl--pop__head").text.strip().replace(" UP", "")
+ dt = datetime.strptime(date_text, "%Y.%m.%d").replace(tzinfo=timezone(timedelta(hours=9)))
+ timestamp = int(dt.timestamp())
- entry = {
- "date": date_text,
- "identifier": "MAIMAIDX_INTL_PRISM",
- "type": None,
- "timestamp": timestamp,
- "headline": None,
- "content": f"New maimai DX International News / maimai DX International の新しいお知らせ\n\n{full_image_url}",
- "url": None,
- "images": [
- {
- "image": full_image_url,
- "link": None
- }
- ]
- }
+ img_tag = item.select_one("a.dl--pop__thumb img")
+ image_url = img_tag["srcset"] if img_tag else None
+ full_image_url = image_url.replace("../", "https://maimai.sega.com/") if image_url else None
- entries.append(entry)
- return entries
+ entry = {
+ "date": date_text,
+ "identifier": identifier,
+ "type": None,
+ "timestamp": timestamp,
+ "headline": None,
+ "content": f"New maimai DX International News / maimai DX International の新しいお知らせ\n\n{full_image_url}",
+ "url": None,
+ "images": [
+ {
+ "image": full_image_url,
+ "link": None
+ }
+ ]
+ }
+ entries.append(entry)
+ return entries
+ if parser == ParserVersion.ALPHA:
+ return alpha_parser
+
+parse_maimaidx_intl_prism_news_site = make_maimaidx_intl_parser("MAIMAIDX_INTL_PRISM", ParserVersion.ALPHA)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage