Neon-AI commited on
Commit
fa75c8d
·
verified ·
1 Parent(s): e986d8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,7 +1,7 @@
1
  from fastapi import FastAPI, HTTPException
2
  import requests
3
  from bs4 import BeautifulSoup
4
-
5
  app = FastAPI(title="Neon Anime Api")
6
 
7
  @app.get("/")
@@ -134,16 +134,18 @@ def get_metadata(path: str):
134
  elif text.startswith("Genres:"):
135
  genres = [g.text.strip() for g in item.find_all("a")]
136
  elif text.startswith("MAL:"):
137
- mal_rating = item.find(text=True, recursive=False).strip()
 
 
138
  elif text.startswith("Duration:"):
139
  duration = item.text.replace("Duration:", "").strip()
140
  elif text.startswith("Episodes:"):
141
  ep_elem = item.find("span")
142
  total_episodes = ep_elem.text.strip() if ep_elem else None
143
  elif text.startswith("Studios:"):
144
- studios = [s.text.strip() for s in item.find_all("span")]
145
  elif text.startswith("Producers:"):
146
- producers = [p.text.strip() for p in item.find_all("span")]
147
 
148
  return {
149
  "title": title,
 
1
  from fastapi import FastAPI, HTTPException
2
  import requests
3
  from bs4 import BeautifulSoup
4
+ import re
5
  app = FastAPI(title="Neon Anime Api")
6
 
7
  @app.get("/")
 
134
  elif text.startswith("Genres:"):
135
  genres = [g.text.strip() for g in item.find_all("a")]
136
  elif text.startswith("MAL:"):
137
+ raw = item.get_text(strip=True) # e.g., "MAL: 7.97 by 1786345 reviews"
138
+ match = re.search(r"MAL:\s*([\d.]+)", raw)
139
+ mal_rating = match.group(1) if match else None
140
  elif text.startswith("Duration:"):
141
  duration = item.text.replace("Duration:", "").strip()
142
  elif text.startswith("Episodes:"):
143
  ep_elem = item.find("span")
144
  total_episodes = ep_elem.text.strip() if ep_elem else None
145
  elif text.startswith("Studios:"):
146
+ studios = list({s.text.strip() for s in soup.select("div.meta div:contains('Studios:') a")})
147
  elif text.startswith("Producers:"):
148
+ producers = list({p.text.strip() for p in soup.select("div.meta div:contains('Producers:') a")})
149
 
150
  return {
151
  "title": title,