Spaces:
Running
on
Zero
Running
on
Zero
Update my_functions.py
Browse files- my_functions.py +23 -21
my_functions.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import yfinance as yf
|
|
|
|
|
2 |
|
3 |
-
# ์์ ์ ํ ์นดํ๋ก๊ทธ
|
4 |
product_catalog = {
|
5 |
"807ZPKBL9V": "SuperWidget",
|
6 |
"1234567890": "MegaGadget"
|
@@ -22,27 +23,28 @@ def get_stock_price(ticker: str) -> float:
|
|
22 |
return data['Close'].iloc[-1]
|
23 |
return float('nan')
|
24 |
|
25 |
-
# ==============================
|
26 |
-
# (New) YouTube ๋์์ ๊ฒ์ ํจ์
|
27 |
-
# ==============================
|
28 |
def search_youtube(query: str) -> str:
|
29 |
"""
|
30 |
-
Searches YouTube for the given query and returns
|
31 |
-
Actual implementation could use YouTube Data API or 'youtube-search-python'.
|
32 |
-
Here we mock the result for demonstration.
|
33 |
"""
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
# link = item['link']
|
42 |
-
# formatted.append(f"{title} - {link}")
|
43 |
-
# return "\n".join(formatted)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import yfinance as yf
|
2 |
+
# youtube-search-python ์ถ๊ฐ ์ํฌํธ
|
3 |
+
from youtubesearchpython import VideosSearch
|
4 |
|
|
|
5 |
product_catalog = {
|
6 |
"807ZPKBL9V": "SuperWidget",
|
7 |
"1234567890": "MegaGadget"
|
|
|
23 |
return data['Close'].iloc[-1]
|
24 |
return float('nan')
|
25 |
|
|
|
|
|
|
|
26 |
def search_youtube(query: str) -> str:
|
27 |
"""
|
28 |
+
Searches YouTube for the given query and returns top 3 video titles & links.
|
|
|
|
|
29 |
"""
|
30 |
+
# youtube-search-python ์ด์ฉ
|
31 |
+
try:
|
32 |
+
videosSearch = VideosSearch(query, limit=3)
|
33 |
+
results = videosSearch.result()["result"] # ์ค์ ๊ฒ์ ๊ฒฐ๊ณผ
|
34 |
+
|
35 |
+
if not results:
|
36 |
+
return "No videos found for your query."
|
|
|
|
|
|
|
37 |
|
38 |
+
# ๊ฒฐ๊ณผ์์ ํ์ดํ๊ณผ ๋งํฌ๋ฅผ ์ถ์ถ
|
39 |
+
formatted_list = []
|
40 |
+
for idx, item in enumerate(results, start=1):
|
41 |
+
title = item.get("title", "No Title")
|
42 |
+
link = item.get("link", "#")
|
43 |
+
formatted_list.append(f"{idx}) [{title}]({link})")
|
44 |
+
|
45 |
+
# ์ฌ๋ฌ ์ค๋ก ๋ฌถ์ด์ ๋ฐํ
|
46 |
+
return "\n".join(formatted_list)
|
47 |
+
|
48 |
+
except Exception as e:
|
49 |
+
# ์ด๋ค ์๋ฌ๋ ๋ฐ์ ์ ์์ ํ๊ฒ ๋ฉ์์ง ๋ฐํ
|
50 |
+
return f"Error searching YouTube: {str(e)}"
|