File size: 3,287 Bytes
926f2d5
 
6a1ce48
16b9ba8
926f2d5
e5264ed
 
926f2d5
e5264ed
459055d
6a1ce48
 
 
 
 
 
 
 
926f2d5
6a1ce48
 
926f2d5
e5264ed
 
926f2d5
 
 
ba2ff4d
926f2d5
6a1ce48
ba2ff4d
7c3228d
926f2d5
ba2ff4d
6a1ce48
 
 
16b9ba8
6a1ce48
 
 
 
926f2d5
 
7c3228d
926f2d5
7c3228d
16b9ba8
926f2d5
4ea95e3
 
 
 
 
 
 
 
 
 
 
 
16b9ba8
4ea95e3
926f2d5
4ea95e3
926f2d5
 
 
 
4118ca8
 
31406cd
 
926f2d5
 
 
e5264ed
 
 
 
 
 
 
 
 
 
 
 
926f2d5
16b9ba8
 
 
 
 
 
 
 
 
926f2d5
26bfbbd
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
import requests
import xml.etree.ElementTree as ET
import time

def get_news_from_rss(rss_url):
    """RSS ํ”ผ๋“œ์—์„œ ๋‰ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค."""
    try:
        response = requests.get(rss_url)
        if response.status_code == 200:
            root = ET.fromstring(response.content)
            items = root.findall(".//item")
            news_list = []
            for item in items:
                title = item.find("title").text
                link = item.find("link").text
                news_list.append({"title": title, "url": link})
            return news_list
    except Exception as e:
        print(f"Error fetching RSS feed: {e}")
    return []

def display_news(news_items):
    """๋‰ด์Šค๋ฅผ ์š”์•ฝ ๋ฐ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค."""
    if not news_items:
        st.warning("๋‰ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
        return

    for item in news_items:
        original_title = item.get('title', '')

        if not original_title:
            continue

        url = item.get('url', '#')  # ๊ธฐ์‚ฌ URL์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ ๋งํฌ๋Š” '#'
        st.markdown(f'''
            <div class="headline-container">
                <a href="{url}" target="_blank" style="text-decoration: none; pointer-events: auto;">
                    <div class="headline-text">{original_title}</div>
                </a>
            </div>
        ''', unsafe_allow_html=True)

def main():
    """์•ฑ ๋ฉ”์ธ ํ•จ์ˆ˜"""
    st.set_page_config(layout="wide")
    
    st.markdown(""" 
        <style>
        .headline-container {
            background-color: rgba(255, 255, 255, 0.9);
            padding: 15px 20px;
            margin: 15px 0;
            border-radius: 3px;
            text-align: center;
        }
        .headline-text {
            color: #000000;
            font-size: 40px;
            font-weight: bold;
            font-family: 'Noto Sans KR', sans-serif;
            pointer-events: auto;  /* ํด๋ฆญ ๊ฐ€๋Šฅํ•˜๋„๋ก ์„ค์ • */
        }
        .stApp {
            background-image: url("https://huggingface.co/spaces/JAMESPARK3/headlineai/resolve/main/news.jpg");
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }
        .stRadio > div > label {
            font-size: 30px;
            font-weight: bold;
        }
        </style>
    """, unsafe_allow_html=True)

    # ๋‰ด์Šค ์„ ํƒ ๋ฒ„ํŠผ ์ถ”๊ฐ€
    news_source = st.sidebar.radio("๋‰ด์Šค ์„ ํƒ", ["jtbc ๋‰ด์Šค", "์—ฐํ•ฉ๋‰ด์Šค", "SBS ๋‰ด์Šค"])

    if news_source == "jtbc ๋‰ด์Šค":
        rss_url = "https://news-ex.jtbc.co.kr/v1/get/rss/issue"
    elif news_source == "์—ฐํ•ฉ๋‰ด์Šค":
        rss_url = "http://www.yonhapnewstv.co.kr/category/news/headline/feed/"
    else:
        rss_url = "https://news.sbs.co.kr/news/headlineRssFeed.do?plink=RSSREADER"

    news_items = get_news_from_rss(rss_url)
    display_news(news_items)

    # ์ƒˆ๋กœ๊ณ ์นจ ํƒ€์ด๋จธ ์„ค์ •
    if 'last_run' not in st.session_state:
        st.session_state.last_run = time.time()

    current_time = time.time()
    if current_time - st.session_state.last_run >= 3600:  # 1์‹œ๊ฐ„ ๊ฒฝ๊ณผ
        st.session_state.last_run = current_time
        st.rerun()  # ์ƒˆ๋กœ๊ณ ์นจ

if __name__ == "__main__":
    main()