huggingsamurai commited on
Commit
e5ba2f7
·
verified ·
1 Parent(s): 3336576

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -27,17 +27,16 @@ def my_custom_tool(arg1:str)-> str: #it's import to specify the return type
27
 
28
  try:
29
  response = requests.get(url, headers=headers)
30
- response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
31
  soup = BeautifulSoup(response.content, "html.parser")
32
  results = soup.find_all("li", class_="booklink")
33
- urls = []
34
- for result in results[:1]: # grabs the top 1
35
- link = result.find("a", class_="link")
36
  if link:
37
  full_url = "https://www.gutenberg.org" + link["href"]
38
- urls.append(full_url)
39
- return urls
40
-
41
  except requests.exceptions.RequestException as e:
42
  print(f"Error: {e}")
43
  return None
 
27
 
28
  try:
29
  response = requests.get(url, headers=headers)
30
+ response.raise_for_status()
31
  soup = BeautifulSoup(response.content, "html.parser")
32
  results = soup.find_all("li", class_="booklink")
33
+ if results: #Check if results are present.
34
+ link = results[0].find("a", class_="link") #Grabs the first result
 
35
  if link:
36
  full_url = "https://www.gutenberg.org" + link["href"]
37
+ return full_url
38
+ return None #Return None if no results, or no link.
39
+
40
  except requests.exceptions.RequestException as e:
41
  print(f"Error: {e}")
42
  return None