CryptoScoutv1 commited on
Commit
25d7a7f
·
verified ·
1 Parent(s): 2c19cee

Create WebScape_TOOL.py

Browse files
Files changed (1) hide show
  1. WebScape_TOOL.py +102 -0
WebScape_TOOL.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.tools import tool
2
+ from bs4 import BeautifulSoup
3
+ import requests
4
+ from langchain.tools import tool
5
+ from duckduckgo_search import DDGS
6
+
7
+ class WebSearchTools:
8
+
9
+ #################################### - DDG SEARCH ENGINE TOOL - ####################################
10
+ @tool("internet_search")
11
+ def internet_search(query: str) -> str:
12
+ """
13
+ Performs an internet search using a DuckDuckGo-like service and returns the results.
14
+
15
+ Parameters:
16
+ query (str): The search query.
17
+
18
+ Returns:
19
+ str: The search results or a message indicating no results were found.
20
+ """
21
+ # Assuming `ddgs` is initialized and ready to use here, with a context manager support
22
+ with DDGS() as ddgs:
23
+ results = [r for r in ddgs.text(query, max_results=3)]
24
+ return results if results else "No results found."
25
+ #################################### - DDG SEARCH ENGINE TOOL - ####################################
26
+
27
+ ####################$################ - BS4 URL SCRAPER TOOL - ############$########################
28
+ @staticmethod
29
+ @tool("process_search_results", return_direct=False)
30
+ def process_search_results(url: str) -> str:
31
+ """
32
+ Processes the content from webpages given a URL using BeautifulSoup.
33
+
34
+ Parameters:
35
+ url (str): The URL to fetch and process.
36
+
37
+ Returns:
38
+ str: The text content of the webpage.
39
+ """
40
+ response = requests.get(url=url)
41
+ if response.status_code == 200:
42
+ soup = BeautifulSoup(response.content, "html.parser")
43
+ return soup.get_text()
44
+ else:
45
+ return "Failed to fetch content."
46
+ ####################$################ - BS4 URL SCRAPER TOOL - ############$########################
47
+
48
+
49
+ # ddgs.text(query,maxresults=4,timelimit="d,w,y", keywords="2024")
50
+
51
+ @tool("forecast search")
52
+ def forecast_search(query: str) -> str:
53
+ """
54
+ **** Note: only pass the cryptocurrency name or symbol into the search query****
55
+
56
+ Parameters:
57
+ query (str): The search query.
58
+
59
+ Returns:
60
+ str: The search results or a message indicating no results were found.
61
+ """
62
+ # Assuming `ddgs` is initialized and ready to use here, with a context manager support
63
+
64
+ maxresults = 5
65
+ with DDGS() as ddgs:
66
+ results = [r for r in ddgs.text(f"site:digitalcoinprice.com/forecast {query}", max_results=maxresults)]
67
+ return results if results else "No results found."
68
+
69
+ @tool("technical signal search")
70
+ def technicalsignals_search(query: str) -> str:
71
+ """
72
+ *** Note - Pass only the cryptocurrency name or symbol in this tool and query*****
73
+
74
+ Parameters:
75
+ query (str): The search query.
76
+
77
+ Returns:
78
+ str: The search results or a message indicating no results were found.
79
+ """
80
+
81
+ # Assuming `ddgs` is initialized and ready to use here, with a context manager support
82
+ with DDGS() as ddgs:
83
+ results = [r for r in ddgs.text(f"site:centralcharts.com trade signals {query}", max_results=5)]
84
+ return results if results else "No results found."
85
+
86
+
87
+ @tool("price target search")
88
+ def pricetargets_search(query: str) -> str:
89
+ """
90
+ *** Note - Pass only the cryptocurrency name or symbol in this tool and query*****
91
+
92
+ Parameters:
93
+ query (str): The search query.
94
+
95
+ Returns:
96
+ str: The search results or a message indicating no results were found.
97
+ """
98
+ # Assuming `ddgs` is initialized and ready to use here, with a context manager support
99
+ with DDGS() as ddgs:
100
+ results = [r for r in ddgs.text(f"site:coincodex.com prediction 2024 {query}", max_results=3)]
101
+ return results if results else "No results found."
102
+