23 lines
807 B
Python
23 lines
807 B
Python
import requests
|
|
import xml.etree.ElementTree as ET
|
|
|
|
class NewsCollector:
|
|
"""
|
|
NAS에서 뉴스를 받지 못할 경우, Windows 서버에서 직접 뉴스를 수집하는 모듈
|
|
(Google News RSS 활용)
|
|
"""
|
|
@staticmethod
|
|
def get_market_news(query="주식 시장"):
|
|
url = f"https://news.google.com/rss/search?q={query}&hl=ko&gl=KR&ceid=KR:ko"
|
|
try:
|
|
resp = requests.get(url, timeout=5)
|
|
root = ET.fromstring(resp.content)
|
|
items = []
|
|
for item in root.findall(".//item")[:5]:
|
|
title = item.find("title").text
|
|
items.append({"title": title, "source": "Google News"})
|
|
return items
|
|
except Exception as e:
|
|
print(f"❌ 뉴스 수집 실패: {e}")
|
|
return []
|