Spaces:
Runtime error
Runtime error
File size: 3,983 Bytes
6f5c495 02b135a 6f5c495 8ef3872 6f5c495 8ef3872 6f5c495 |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#python.exe -m pip install --upgrade pip
#pip install feedparser
#pip install newspaper3k
#pip install streamlit
# streamlit run <app.py> for one app
# python run_all.py <folder_path> for multiple apps
import streamlit as st
import feedparser
from urllib.parse import quote
# import streamlit.state as state
st.set_page_config(layout="wide")
#st.markdown("<h2 style='text-align: center; font-family: Verdana; color: red;'>Tin tức tổng hợp 24h qua</h2><br>", unsafe_allow_html=True)
#st.markdown("<h4 style='text-align: center;'>Tìm kiếm theo từ khóa hoặc tên báo (ví dụ: Hà Nội, Vaccine, Mạng xã hội, Trí tuệ nhân tạo, cafebiz.vn, Mỹ...)</h4><br>", unsafe_allow_html=True)
#-----------------------------------------------------------------------------------
# Báo tiếng Việt
#-----------------------------------------------------------------------------------
st.sidebar.title("Báo tiếng Việt")
# Custom keywords
keyword = st.sidebar.text_input("Nhập/Xóa từ khóa", "AI")
# Select websites
list = ['cafebiz.vn', 'cafef.vn', 'thanhnien.vn','vnexpress.net','soha.vn','zingnews.vn','tuoitre.vn','laodong.vn', 'All']
domain = st.sidebar.multiselect("Chọn websites:",list,default=["All"])
sites = ""
if "All" in domain:
domain = ""
if domain:
for i in domain[:-1]:
sites = sites + "site:{} OR ".format(i)
sites = sites + "site:" + domain[-1]
query = keyword + " " + sites + " "
if keyword == "" and sites == "":
query = "Hà Nội"
#st.sidebar.write(query)
#-----------------------------------------------------------------------------------
if st.sidebar.button('Tìm kiếm 🔎'):
url = 'https://news.google.com/rss/search?q=' + quote(query) + 'when:1d&hl=vi'
#st.sidebar.write(url)
feed = feedparser.parse(url)
i = 1
html = ""
for post in feed.entries:
html = html + f"{post.title[:120]} <a href='{post.link}' target='_blank' > Link </a><br>"
if (i % 5 == 0):
html = html + "<br>"
i = i+1
html1 = f"""
<p style='font-size: 17px; font-family: Segoe UI;color:#202124'>
{html}
</p>
"""
st.markdown("<h2 style='text-align: center; font-family: Verdana; color: red;'>Tin tức 24h</h2><br>", unsafe_allow_html=True)
st.markdown(html1, unsafe_allow_html=True)
#-----------------------------------------------------------------------------------
# Báo tiếng Anh
#-----------------------------------------------------------------------------------
st.sidebar.write("-------------------------------")
st.sidebar.title("English News")
# Custom keywords
keyword_en = st.sidebar.text_input("Input/Delete keyword", "AI")
# Select websites
list_en = ['bbc.com','martechseries.com','bloomberg.com', 'cnn.com','cnbc.com','reuters.com','foxnews.com','.entrepreneur.com','techradar.com', 'All']
domain_en = st.sidebar.multiselect("Select websites:",list_en,default=["All"])
sites_en = ""
if "All" in domain_en:
domain_en = ""
if domain_en:
for i in domain[:-1]:
sites_en = sites_en + "site:{} OR ".format(i)
sites_en = sites_en + "site:" + domain_en[-1]
query_en = keyword_en + " " + sites_en + " "
if keyword_en == "" and sites_en == "":
query = "Vaccine"
#-----------------------------------------------------------------------------------
if st.sidebar.button('Search 🔎'):
url_en = 'https://news.google.com/rss/search?q=' + quote(query_en) + 'when:1d&hl=en&gl=US'
#st.sidebar.write(url)
feed_en = feedparser.parse(url_en)
i = 1
html = ""
for post_en in feed_en.entries:
html = html + f"{post_en.title[:120]} <a href='{post_en.link}' target='_blank' > Link </a><br>"
if (i % 5 == 0):
html = html + "<br>"
i = i+1
html1 = f"""
<p style='font-size: 17px; font-family: Segoe UI;color:#202124'>
{html}
</p>
"""
st.markdown("<h2 style='text-align: center; font-family: Verdana; color: red;'>News 24h</h2><br>", unsafe_allow_html=True)
st.markdown(html1, unsafe_allow_html=True)
#st.sidebar.title(url_en) |