Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,562 Bytes
f812981 38f3be9 7fd7317 cb99b4d 38f3be9 cb99b4d 38f3be9 cb99b4d 38f3be9 |
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 |
import yfinance as yf
# youtube-search-python ์ถ๊ฐ ์ํฌํธ
from youtubesearchpython import VideosSearch
product_catalog = {
"807ZPKBL9V": "SuperWidget",
"1234567890": "MegaGadget"
}
def get_product_name_by_PID(PID: str) -> str:
"""
Finds the name of a product by its Product ID
"""
return product_catalog.get(PID, "Unknown product")
def get_stock_price(ticker: str) -> float:
"""
Retrieves the latest stock price for a given ticker using yfinance.
"""
stock = yf.Ticker(ticker)
data = stock.history(period="1d")
if not data.empty:
return data['Close'].iloc[-1]
return float('nan')
def search_youtube(query: str) -> str:
"""
Searches YouTube for the given query and returns top 3 video titles & links.
"""
# youtube-search-python ์ด์ฉ
try:
videosSearch = VideosSearch(query, limit=3)
results = videosSearch.result()["result"] # ์ค์ ๊ฒ์ ๊ฒฐ๊ณผ
if not results:
return "No videos found for your query."
# ๊ฒฐ๊ณผ์์ ํ์ดํ๊ณผ ๋งํฌ๋ฅผ ์ถ์ถ
formatted_list = []
for idx, item in enumerate(results, start=1):
title = item.get("title", "No Title")
link = item.get("link", "#")
formatted_list.append(f"{idx}) [{title}]({link})")
# ์ฌ๋ฌ ์ค๋ก ๋ฌถ์ด์ ๋ฐํ
return "\n".join(formatted_list)
except Exception as e:
# ์ด๋ค ์๋ฌ๋ ๋ฐ์ ์ ์์ ํ๊ฒ ๋ฉ์์ง ๋ฐํ
return f"Error searching YouTube: {str(e)}"
|