diff options
Diffstat (limited to 'bemani')
| -rw-r--r-- | bemani/iidx.py | 60 | ||||
| -rw-r--r-- | bemani/sdvx.py | 46 |
2 files changed, 106 insertions, 0 deletions
diff --git a/bemani/iidx.py b/bemani/iidx.py new file mode 100644 index 0000000..e20dd7d --- /dev/null +++ b/bemani/iidx.py @@ -0,0 +1,60 @@ +from bs4 import BeautifulSoup +from datetime import datetime +from urllib.parse import urljoin +import re + + +def parse_pinky_crush_news_site(html: str, base_url): + type_map = { + "i_01": "NEWSONG", + "i_02": "RANKING", + "i_03": "EVENT", + "i_04": "SHOP", + "i_05": "OTHER" + } + soup = BeautifulSoup(html, "html.parser") + news_items = [] + + for li in soup.select("#info-news > li"): + date_elem = li.select_one(".news-main > li:nth-of-type(1)") + headline_elem = li.select_one(".news-main > li:nth-of-type(2)") + content_elem = li.select_one(".news-main > li:nth-of-type(3)") + type_class = li.get("class", [None])[0] + if not (date_elem and content_elem): + continue + date_str = date_elem.text.strip() + try: + dt = datetime.strptime(date_str, "%Y/%m/%d") + timestamp = int(dt.timestamp()) + except ValueError: + timestamp = None + + headline = headline_elem.a.text.strip() if headline_elem.a else headline_elem.text.strip() + + for a in content_elem.select("a[href]"): + href = urljoin(base_url, a["href"]) + text = a.get_text(strip=True) + a.replace_with(f"[{text}]({href})") + + for br in content_elem.find_all("br"): + br.replace_with("\n") + + content = content_elem.get_text().strip() + + content = content.replace( + " e-amusement ベーシックコース ", + " e-amusement ベーシックコース " + ) + content = content.replace("※", "\n※") + content = re.sub(r"\n[ \t]+", "\n", content) + content = re.sub(r'\s*/\s*', '/', content) + news_items.append({ + "date": date_str, + "type": type_map[type_class], + "timestamp": timestamp, + "headline": headline, + "content": content, + "images": [], + }) + + return news_items diff --git a/bemani/sdvx.py b/bemani/sdvx.py new file mode 100644 index 0000000..55d97ef --- /dev/null +++ b/bemani/sdvx.py @@ -0,0 +1,46 @@ +from bs4 import BeautifulSoup +from datetime import datetime +from urllib.parse import urljoin + +def parse_exceed_gear_news_site(html: str, base_url: str): + soup = BeautifulSoup(html, 'html.parser') + news_list = soup.select('.tab ul.news li') + + entries = [] + for li in news_list: + date = li.select_one('strong') + pre = li.select_one('pre') + + if not date or not pre: + continue + date_str = date.text.strip() + try: + dt = datetime.strptime(date_str, "%Y.%m.%d") + timestamp = int(dt.timestamp()) + except ValueError: + timestamp = None + headline = li.select_one('p.notice') + headline_text = headline.text.strip() if headline else None + for tag in pre.select('font, b, u, span'): + tag.unwrap() + content = pre.get_text(separator='\n', strip=True) + images = [] + for img in pre.select('img'): + src = img.get('data-original') or img.get('src') + if not src or src.startswith('data:'): + continue + src = urljoin(base_url, src) + parent = img.find_parent('a') + href = urljoin(base_url, parent['href']) if parent and parent.has_attr('href') else None + images.append({'image': src, 'link': href}) + + entries.append({ + 'date': date_str, + 'type': None, + 'timestamp': timestamp, + 'headline': headline_text, + 'content': content, + 'images': images + }) + + return entries |
