From dff3adb12efae4bf0f5a5d7e353a3e5b9679552c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 10 Feb 2025 00:58:41 -0800 Subject: chore: rename json generator script --- generate_json.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ main.py | 45 --------------------------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 generate_json.py delete mode 100644 main.py diff --git a/generate_json.py b/generate_json.py new file mode 100644 index 0000000..579cfdc --- /dev/null +++ b/generate_json.py @@ -0,0 +1,45 @@ +import requests +import bs4 +import json + +response = requests.get("https://hololist.net/hololive-birthdays/") + +response.raise_for_status() + +birthdays = [] + +for month_div in bs4.BeautifulSoup(response.text, "html.parser").find_all( + "div", {"label": "month"} +): + month = int(month_div["id"]) + + for row in month_div.find_all("div", class_="row"): + for entry in row.find_all("div", class_="col-12"): + # Day + day_tag = entry.find("h3", class_="fs-6") + day = int(day_tag.text.split()[-1]) if day_tag else None + + # Name and profile URL + profile_tag = entry.find("a", class_="line-truncate") + name = profile_tag.text.strip() if profile_tag else None + profile_url = profile_tag["href"] if profile_tag else None + + # Picture URL + img_tag = entry.find("img", class_="lazy-image") + picture_url = ( + img_tag["data-src"] if img_tag and "data-src" in img_tag.attrs else None + ) + + if day and name and profile_url and picture_url: + birthdays.append( + { + "month": month, + "day": day, + "name": name, + "pictureURL": picture_url, + "profileURL": profile_url, + } + ) + +with open("hololive_birthdays.json", "w", encoding="utf-8") as json_file: + json.dump(birthdays, json_file, ensure_ascii=False, indent=4) diff --git a/main.py b/main.py deleted file mode 100644 index 579cfdc..0000000 --- a/main.py +++ /dev/null @@ -1,45 +0,0 @@ -import requests -import bs4 -import json - -response = requests.get("https://hololist.net/hololive-birthdays/") - -response.raise_for_status() - -birthdays = [] - -for month_div in bs4.BeautifulSoup(response.text, "html.parser").find_all( - "div", {"label": "month"} -): - month = int(month_div["id"]) - - for row in month_div.find_all("div", class_="row"): - for entry in row.find_all("div", class_="col-12"): - # Day - day_tag = entry.find("h3", class_="fs-6") - day = int(day_tag.text.split()[-1]) if day_tag else None - - # Name and profile URL - profile_tag = entry.find("a", class_="line-truncate") - name = profile_tag.text.strip() if profile_tag else None - profile_url = profile_tag["href"] if profile_tag else None - - # Picture URL - img_tag = entry.find("img", class_="lazy-image") - picture_url = ( - img_tag["data-src"] if img_tag and "data-src" in img_tag.attrs else None - ) - - if day and name and profile_url and picture_url: - birthdays.append( - { - "month": month, - "day": day, - "name": name, - "pictureURL": picture_url, - "profileURL": profile_url, - } - ) - -with open("hololive_birthdays.json", "w", encoding="utf-8") as json_file: - json.dump(birthdays, json_file, ensure_ascii=False, indent=4) -- cgit v1.2.3