File size: 1,438 Bytes
d2100e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import feedparser
import requests
from bs4 import BeautifulSoup
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage

def test():
    rss_url = "https://news.google.com/rss/search?q=%EA%B8%88&hl=ko&gl=KR&ceid=KR:ko"
    feed = feedparser.parse(rss_url)
    if not feed.entries:
        return
    entry = feed.entries[0]
    print("Link:", entry.link)
    
    try:
        # fetch
        r = requests.get(entry.link, timeout=10, headers={'User-Agent': 'Mozilla/5.0'})
        soup = BeautifulSoup(r.text, 'html.parser')
        text = soup.get_text(separator=' ', strip=True)
        print("Text preview:", text[:200])
        
        # Test Gemini
        llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0.1)
        
        prompt = f"""
๋‹ค์Œ์€ ๋‰ด์Šค ๊ธฐ์‚ฌ ์›๋ฌธ์ž…๋‹ˆ๋‹ค:
{text[:3000]}

์ด ๋‰ด์Šค๊ฐ€ ๊ธˆ(Gold, ๊ท€๊ธˆ์†/ํˆฌ์ž์ž์‚ฐ)๊ณผ ๊ด€๋ จ๋œ ์‹ค์ œ ๋‰ด์Šค์ธ์ง€ ํŒ๋ณ„ํ•˜๊ณ , 
๋งž๋‹ค๋ฉด ๊ธฐ์‚ฌ์˜ ํ•ต์‹ฌ ๋‚ด์šฉ์„ 1~2์ค„๋กœ ์š”์•ฝํ•ด์ฃผ์„ธ์š”.
๋งŒ์•ฝ ๊ธˆ๊ณผ ์ „ํ˜€ ๊ด€๋ จ์ด ์—†๋Š” ๋‰ด์Šค๋ผ๋ฉด (์˜ˆ: ๊ธˆ์š”์ผ, ์†ก๊ธˆ, ์‹œ์„ธ ์—†๋Š” ์ผ๋ฐ˜ ๊ธฐ์‚ฌ ๋“ฑ) 
'NOT_GOLD_NEWS' ๋ผ๊ณ ๋งŒ ์ •ํ™•ํžˆ ๋‹ต๋ณ€ํ•˜์„ธ์š”.

์š”์•ฝ ๊ฒฐ๊ณผ:
"""
        response = llm.invoke([HumanMessage(content=prompt)])
        print("\nGemini Response:", response.content)
    except Exception as e:
        print("Error:", e)

if __name__ == "__main__":
    test()