File size: 1,746 Bytes
77c658d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from smolagents import Tool
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from markdownify import markdownify as md
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

class GetSVGList(Tool):
    name = "get_svg_list"
    description = "Get list of svg available to generate it with GetSVG Tool"

    inputs = {

    }

    output_type = "array"

    def forward(self) -> str:
        chrome_options = Options()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument("--disable-dev-shm-usage")
        chrome_options.add_argument(
            "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
            "AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/114.0.0.0 Safari/537.36"
        )

        driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_options)

        try:
            url = "https://phosphoricons.com/"
            driver.get(url)

            wait = WebDriverWait(driver, 10)
            name_elements = wait.until(
                EC.presence_of_all_elements_located((By.CSS_SELECTOR, "span.name"))
            )

            icon_names = [el.text.strip() for el in name_elements if el.text.strip()]
            return icon_names
            if not icon_names:
                return "Aucun nom d'icône trouvé."

            return "\n".join(icon_names)
        finally:
            driver.quit()