Initial commit - cleaned repository
This commit is contained in:
115
backup-services/rss-feed/backend/app/google_rss.py
Normal file
115
backup-services/rss-feed/backend/app/google_rss.py
Normal file
@ -0,0 +1,115 @@
|
||||
"""
|
||||
Google News RSS Feed Generator
|
||||
구글 뉴스 RSS 피드 URL 생성 및 구독 지원
|
||||
"""
|
||||
from typing import Optional, List
|
||||
from urllib.parse import quote_plus
|
||||
from enum import Enum
|
||||
|
||||
class GoogleNewsCategory(str, Enum):
|
||||
"""구글 뉴스 카테고리"""
|
||||
WORLD = "WORLD"
|
||||
NATION = "NATION"
|
||||
BUSINESS = "BUSINESS"
|
||||
TECHNOLOGY = "TECHNOLOGY"
|
||||
ENTERTAINMENT = "ENTERTAINMENT"
|
||||
SPORTS = "SPORTS"
|
||||
SCIENCE = "SCIENCE"
|
||||
HEALTH = "HEALTH"
|
||||
|
||||
class GoogleNewsRSS:
|
||||
"""Google News RSS 피드 URL 생성기"""
|
||||
|
||||
BASE_URL = "https://news.google.com/rss"
|
||||
|
||||
@staticmethod
|
||||
def search_feed(query: str, lang: str = "ko", country: str = "KR") -> str:
|
||||
"""
|
||||
키워드 검색 RSS 피드 URL 생성
|
||||
|
||||
Args:
|
||||
query: 검색 키워드
|
||||
lang: 언어 코드 (ko, en, ja, zh-CN 등)
|
||||
country: 국가 코드 (KR, US, JP, CN 등)
|
||||
|
||||
Returns:
|
||||
RSS 피드 URL
|
||||
"""
|
||||
encoded_query = quote_plus(query)
|
||||
return f"{GoogleNewsRSS.BASE_URL}/search?q={encoded_query}&hl={lang}&gl={country}&ceid={country}:{lang}"
|
||||
|
||||
@staticmethod
|
||||
def topic_feed(category: GoogleNewsCategory, lang: str = "ko", country: str = "KR") -> str:
|
||||
"""
|
||||
카테고리별 RSS 피드 URL 생성
|
||||
|
||||
Args:
|
||||
category: 뉴스 카테고리
|
||||
lang: 언어 코드
|
||||
country: 국가 코드
|
||||
|
||||
Returns:
|
||||
RSS 피드 URL
|
||||
"""
|
||||
return f"{GoogleNewsRSS.BASE_URL}/headlines/section/topic/{category.value}?hl={lang}&gl={country}&ceid={country}:{lang}"
|
||||
|
||||
@staticmethod
|
||||
def location_feed(location: str, lang: str = "ko", country: str = "KR") -> str:
|
||||
"""
|
||||
지역 뉴스 RSS 피드 URL 생성
|
||||
|
||||
Args:
|
||||
location: 지역명 (예: Seoul, 서울, New York)
|
||||
lang: 언어 코드
|
||||
country: 국가 코드
|
||||
|
||||
Returns:
|
||||
RSS 피드 URL
|
||||
"""
|
||||
encoded_location = quote_plus(location)
|
||||
return f"{GoogleNewsRSS.BASE_URL}/headlines/section/geo/{encoded_location}?hl={lang}&gl={country}&ceid={country}:{lang}"
|
||||
|
||||
@staticmethod
|
||||
def trending_feed(lang: str = "ko", country: str = "KR") -> str:
|
||||
"""
|
||||
트렌딩 뉴스 RSS 피드 URL 생성
|
||||
|
||||
Args:
|
||||
lang: 언어 코드
|
||||
country: 국가 코드
|
||||
|
||||
Returns:
|
||||
RSS 피드 URL
|
||||
"""
|
||||
return f"{GoogleNewsRSS.BASE_URL}?hl={lang}&gl={country}&ceid={country}:{lang}"
|
||||
|
||||
@staticmethod
|
||||
def get_common_feeds() -> List[dict]:
|
||||
"""
|
||||
자주 사용되는 RSS 피드 목록 반환
|
||||
|
||||
Returns:
|
||||
피드 정보 리스트
|
||||
"""
|
||||
return [
|
||||
{
|
||||
"title": "구글 뉴스 - 한국 헤드라인",
|
||||
"url": GoogleNewsRSS.trending_feed("ko", "KR"),
|
||||
"description": "한국 주요 뉴스"
|
||||
},
|
||||
{
|
||||
"title": "구글 뉴스 - 기술",
|
||||
"url": GoogleNewsRSS.topic_feed(GoogleNewsCategory.TECHNOLOGY, "ko", "KR"),
|
||||
"description": "기술 관련 뉴스"
|
||||
},
|
||||
{
|
||||
"title": "구글 뉴스 - 비즈니스",
|
||||
"url": GoogleNewsRSS.topic_feed(GoogleNewsCategory.BUSINESS, "ko", "KR"),
|
||||
"description": "비즈니스 뉴스"
|
||||
},
|
||||
{
|
||||
"title": "Google News - World",
|
||||
"url": GoogleNewsRSS.topic_feed(GoogleNewsCategory.WORLD, "en", "US"),
|
||||
"description": "World news in English"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user