diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-10-16 11:24:21 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-10-16 11:25:16 -0700 |
| commit | 9aeca20449d6b4083d53b510ef8ab819bde43846 (patch) | |
| tree | 6a4b5d0fdae6dd35d6823a7572d61e0fec46d4c4 /konami | |
| parent | c0d7eea69ea3885f97c6ccc0525a3318efd2ab6a (diff) | |
migrate all eamuse app feed games to scrape api route
Diffstat (limited to 'konami')
| -rw-r--r-- | konami/eamuse_app.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/konami/eamuse_app.py b/konami/eamuse_app.py index d7a9b3a..f3cc643 100644 --- a/konami/eamuse_app.py +++ b/konami/eamuse_app.py @@ -1,11 +1,15 @@ from bs4 import BeautifulSoup from datetime import datetime from urllib.parse import urljoin +import json import time BASE_URL = "https://eam.573.jp" def parse_news_page(html: str, identifier: str): + """ + Legacy method of scraping. Should not be used if API method works since it will be much faster + """ soup = BeautifulSoup(html, "html.parser") entries = [] @@ -50,3 +54,34 @@ def parse_news_page(html: str, identifier: str): entries.append(entry) return entries + +def parse_news_api_route(raw_api_data: str, identifier: str, eam_news_site: str=""): + """ + Re-maps eamuse news app API routes to 573Updates JSON + """ + route_data = json.loads(raw_api_data) + entries = [] + for post_data in route_data["post_list"]: + date_str = post_data["entry_date"] + timestamp = post_data["entry_time"] + content = post_data["content"] + url = eam_news_site + "?post_id="+post_data["post_id"] + images = [] + if "image_url" in post_data: + images = [{ + "image": post_data["image_url"], + "link": url + }] + entry = { + "date": date_str, + "identifier": identifier, + "type": None, + "timestamp": timestamp, + "headline": None, + "content": content, + "url": url, + "images": images, + "is_ai_summary": False + } + entries.append(entry) + return entries |
