ginipick commited on
Commit
38f3be9
ยท
verified ยท
1 Parent(s): d989de5

Update my_functions.py

Browse files
Files changed (1) hide show
  1. 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 a short list of video titles/links.
31
- Actual implementation could use YouTube Data API or 'youtube-search-python'.
32
- Here we mock the result for demonstration.
33
  """
34
- # ์‹ค์ „ ์˜ˆ์‹œ (youtube-search-python ์‚ฌ์šฉ ์‹œ):
35
- # from youtubesearchpython import VideosSearch
36
- # videosSearch = VideosSearch(query, limit=3)
37
- # results = videosSearch.result()['result']
38
- # formatted = []
39
- # for item in results:
40
- # title = item['title']
41
- # link = item['link']
42
- # formatted.append(f"{title} - {link}")
43
- # return "\n".join(formatted)
44
 
45
- # -- ๋ฐ๋ชจ์šฉ ๋”๋ฏธ ๊ฒฐ๊ณผ --
46
- return (
47
- "[Demo Video](https://www.youtube.com/watch?v=JzjR5LGOvqg)\n"
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)}"