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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -8,10 +8,23 @@ app = FastAPI(title="Neon Anime Api")
8
  def home():
9
  return {"status": "Neon Anime Api Alive"}
10
 
 
 
 
 
 
 
 
 
 
 
11
  @app.get("/search")
12
  def search_anime(keyword: str):
13
  try:
14
- url = f"https://www.aniwave.se/filter?keyword={keyword}"
 
 
 
15
  headers = {"User-Agent": "Mozilla/5.0"}
16
  resp = requests.get(url, headers=headers)
17
  if resp.status_code != 200:
 
8
  def home():
9
  return {"status": "Neon Anime Api Alive"}
10
 
11
+ def normalize_text(text: str) -> str:
12
+ # Lowercase everything
13
+ text = text.lower()
14
+ # Remove all characters except letters, numbers, and spaces
15
+ text = re.sub(r"[^a-z0-9\s]", "", text)
16
+ # Collapse multiple spaces into one
17
+ text = re.sub(r"\s+", " ", text)
18
+ # Trim spaces at the start and end
19
+ return text.strip()
20
+
21
  @app.get("/search")
22
  def search_anime(keyword: str):
23
  try:
24
+ # Normalize the keyword
25
+ normalized_keyword = normalize_text(keyword)
26
+
27
+ url = f"https://www.aniwave.se/filter?keyword={normalized_keyword}"
28
  headers = {"User-Agent": "Mozilla/5.0"}
29
  resp = requests.get(url, headers=headers)
30
  if resp.status_code != 200: