dvt81 commited on
Commit
7ce227f
·
verified ·
1 Parent(s): db85dcc

testing with simpler function

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -13,11 +13,11 @@ from selenium.webdriver.chrome.service import Service
13
  from webdriver_manager.chrome import ChromeDriverManager
14
 
15
  @tool
16
- def get_zh_top_news() -> tuple[str, str]:
17
  """A tool that retrieves the current top news article's title and URL from www.zerohedge.com.
18
 
19
  Returns:
20
- tuple[str, str]: A tuple containing the article title (str) and its URL (str).
21
 
22
  Raises:
23
  Exception: If the page fails to load or the expected element is not found.
@@ -39,17 +39,19 @@ def get_zh_top_news() -> tuple[str, str]:
39
  # Find the first <h2> with class starting with 'Article_title___'
40
  top_article = driver.find_element(By.CSS_SELECTOR, "h2[class^='Article_title___']")
41
 
 
 
42
  # Extract the title from the <a> tag inside the <h2>
43
  article_title = top_article.find_element(By.TAG_NAME, "a").text.strip()
44
 
45
  # Extract the URL from the href attribute of the <a> tag
46
  article_link = top_article.find_element(By.TAG_NAME, "a").get_attribute("href")
47
-
48
  # Ensure the link is absolute
49
  if not article_link.startswith("http"):
50
  article_link = f"https://www.zerohedge.com{article_link}"
51
 
52
- return article_title, article_link
53
 
54
  except Exception as e:
55
  print(f"Error retrieving top headline: {e}")
 
13
  from webdriver_manager.chrome import ChromeDriverManager
14
 
15
  @tool
16
+ def get_zh_top_news() -> str:
17
  """A tool that retrieves the current top news article's title and URL from www.zerohedge.com.
18
 
19
  Returns:
20
+ str: the article title (str)
21
 
22
  Raises:
23
  Exception: If the page fails to load or the expected element is not found.
 
39
  # Find the first <h2> with class starting with 'Article_title___'
40
  top_article = driver.find_element(By.CSS_SELECTOR, "h2[class^='Article_title___']")
41
 
42
+ print(f" article object: {top_article}")
43
+
44
  # Extract the title from the <a> tag inside the <h2>
45
  article_title = top_article.find_element(By.TAG_NAME, "a").text.strip()
46
 
47
  # Extract the URL from the href attribute of the <a> tag
48
  article_link = top_article.find_element(By.TAG_NAME, "a").get_attribute("href")
49
+
50
  # Ensure the link is absolute
51
  if not article_link.startswith("http"):
52
  article_link = f"https://www.zerohedge.com{article_link}"
53
 
54
+ return article_title
55
 
56
  except Exception as e:
57
  print(f"Error retrieving top headline: {e}")