주식자동매매 AI 프로그램 초기 모델
This commit is contained in:
22
modules/services/news.py
Normal file
22
modules/services/news.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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 []
|
||||
Reference in New Issue
Block a user