gnumanth commited on
Commit
a38d810
·
verified ·
1 Parent(s): 37828a6

feat: search titles and title

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -68,10 +68,11 @@ def search_xkcd_transcript(search_term: str) -> str:
68
  matches = []
69
  search_term_lower = search_term.lower()
70
 
71
- # Search through more comics (last 200 for better results)
72
- start_num = max(1, latest_num - 199)
 
73
 
74
- for comic_num in range(start_num, latest_num + 1):
75
  try:
76
  url = f"https://xkcd.com/{comic_num}/info.0.json"
77
  response = requests.get(url, timeout=5)
@@ -91,6 +92,10 @@ def search_xkcd_transcript(search_term: str) -> str:
91
  "img": comic_data["img"]
92
  })
93
 
 
 
 
 
94
  except:
95
  continue # Skip comics that can't be fetched
96
 
 
68
  matches = []
69
  search_term_lower = search_term.lower()
70
 
71
+ # Search through comics that are more likely to have transcripts (1-1600 range)
72
+ # Recent comics often don't have transcripts, so we search older ones first
73
+ max_search_range = min(1600, latest_num)
74
 
75
+ for comic_num in range(1, max_search_range + 1):
76
  try:
77
  url = f"https://xkcd.com/{comic_num}/info.0.json"
78
  response = requests.get(url, timeout=5)
 
92
  "img": comic_data["img"]
93
  })
94
 
95
+ # Limit results to prevent long search times
96
+ if len(matches) >= 20:
97
+ break
98
+
99
  except:
100
  continue # Skip comics that can't be fetched
101