Skip to content

Commit

Permalink
fix name outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrErde committed Jun 28, 2024
1 parent dcb6f58 commit 059c790
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions script/fetch_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

url = "https://subwaysurf.fandom.com/wiki/Player_Profile"

filename = "upload/playerprofile_links.json"


def fetch_data(url):
try:
Expand Down Expand Up @@ -32,7 +34,15 @@ def fetch_profile(html):
if img_tag:
img_src = img_tag.get("data-src", "") or img_tag.get("src", "")
img_src = img_src.split(".png")[0] + ".png"
profile_name = item.find("div", class_="lightbox-caption").text.strip()

# Fetch the title from the anchor tag within the lightbox-caption div
lightbox_caption_div = item.find("div", class_="lightbox-caption")
if lightbox_caption_div:
anchor_tag = lightbox_caption_div.find("a")
profile_name = (
anchor_tag.get("title", "").strip() if anchor_tag else ""
)

profiles.append({"name": profile_name, "img_url": img_src})

return profiles
Expand All @@ -51,24 +61,27 @@ def fetch_frame(html):
raise ValueError("Gallery div with id 'gallery-2' not found")

items = gallery_div.find_all("div", class_="wikia-gallery-item")
profiles = []
frames = []

for item in items:
img_tag = item.find("div", class_="gallery-image-wrapper").find("img")
if img_tag:
img_src = img_tag.get("data-src", "") or img_tag.get("src", "")
img_src = img_src.split(".png")[0] + ".png"
profile_name = item.find("div", class_="lightbox-caption").text.strip()
profiles.append({"name": profile_name, "img_url": img_src})
frame_name = item.find("div", class_="lightbox-caption").text.strip()
frame_name = frame_name.split(" (from ")[
0
] # Remove " (from " and everything after it
frames.append({"name": frame_name, "img_url": img_src})

return profiles
return frames

except Exception as e:
print("Error fetching frame:", e)
return []


def save_json(portraits, frames, filename="upload/playerprofile_links.json"):
def save_json(portraits, frames):
data = {"Portraits": portraits, "Frames": frames}

with open(filename, "w") as f:
Expand Down

0 comments on commit 059c790

Please sign in to comment.