Spaces:
Runtime error
Runtime error
Commit
·
6f5c495
1
Parent(s):
c3991a5
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
#python.exe -m pip install --upgrade pip
|
| 5 |
+
#pip install feedparser
|
| 6 |
+
#pip install newspaper3k
|
| 7 |
+
#pip install streamlit
|
| 8 |
+
|
| 9 |
+
# streamlit run <app.py> for one app
|
| 10 |
+
# python run_all.py <folder_path> for multiple apps
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
import streamlit as st
|
| 14 |
+
import feedparser
|
| 15 |
+
from urllib.parse import quote
|
| 16 |
+
import streamlit.state as state
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
st.set_page_config(layout="wide")
|
| 20 |
+
#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)
|
| 21 |
+
#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)
|
| 22 |
+
#-----------------------------------------------------------------------------------
|
| 23 |
+
# Báo tiếng Việt
|
| 24 |
+
#-----------------------------------------------------------------------------------
|
| 25 |
+
st.sidebar.title("Báo tiếng Việt")
|
| 26 |
+
# Custom keywords
|
| 27 |
+
keyword = st.sidebar.text_input("Nhập/Xóa từ khóa", "Hà Nội")
|
| 28 |
+
|
| 29 |
+
# Select websites
|
| 30 |
+
list = ['cafebiz.vn', 'cafef.vn', 'thanhnien.vn','vnexpress.net','soha.vn','zingnews.vn','tuoitre.vn','laodong.vn', 'All']
|
| 31 |
+
domain = st.sidebar.multiselect("Chọn websites:",list,default=["All"])
|
| 32 |
+
|
| 33 |
+
sites = ""
|
| 34 |
+
if "All" in domain:
|
| 35 |
+
domain = ""
|
| 36 |
+
if domain:
|
| 37 |
+
for i in domain[:-1]:
|
| 38 |
+
sites = sites + "site:{} OR ".format(i)
|
| 39 |
+
sites = sites + "site:" + domain[-1]
|
| 40 |
+
|
| 41 |
+
query = keyword + " " + sites + " "
|
| 42 |
+
|
| 43 |
+
if keyword == "" and sites == "":
|
| 44 |
+
query = "Hà Nội"
|
| 45 |
+
|
| 46 |
+
#st.sidebar.write(query)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
#-----------------------------------------------------------------------------------
|
| 51 |
+
if st.sidebar.button('Tìm kiếm 🔎'):
|
| 52 |
+
|
| 53 |
+
url = 'https://news.google.com/rss/search?q=' + quote(query) + 'when:1d&hl=vi'
|
| 54 |
+
#st.sidebar.write(url)
|
| 55 |
+
|
| 56 |
+
feed = feedparser.parse(url)
|
| 57 |
+
|
| 58 |
+
i = 1
|
| 59 |
+
html = ""
|
| 60 |
+
for post in feed.entries:
|
| 61 |
+
|
| 62 |
+
html = html + f"{post.title[:120]} <a href='{post.link}' target='_blank' > Link </a><br>"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if (i % 5 == 0):
|
| 66 |
+
html = html + "<br>"
|
| 67 |
+
i = i+1
|
| 68 |
+
|
| 69 |
+
html1 = f"""
|
| 70 |
+
<p style='font-size: 17px; font-family: Segoe UI;color:#202124'>
|
| 71 |
+
{html}
|
| 72 |
+
</p>
|
| 73 |
+
"""
|
| 74 |
+
st.markdown("<h2 style='text-align: center; font-family: Verdana; color: red;'>Tin tức 24h</h2><br>", unsafe_allow_html=True)
|
| 75 |
+
st.markdown(html1, unsafe_allow_html=True)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
#-----------------------------------------------------------------------------------
|
| 80 |
+
# Báo tiếng Anh
|
| 81 |
+
#-----------------------------------------------------------------------------------
|
| 82 |
+
st.sidebar.write("-------------------------------")
|
| 83 |
+
st.sidebar.title("English News")
|
| 84 |
+
# Custom keywords
|
| 85 |
+
keyword_en = st.sidebar.text_input("Input/Delete keyword", "AI")
|
| 86 |
+
|
| 87 |
+
# Select websites
|
| 88 |
+
list_en = ['bbc.com','martechseries.com','bloomberg.com', 'cnn.com','cnbc.com','reuters.com','foxnews.com','.entrepreneur.com','techradar.com', 'All']
|
| 89 |
+
domain_en = st.sidebar.multiselect("Select websites:",list_en,default=["All"])
|
| 90 |
+
|
| 91 |
+
sites_en = ""
|
| 92 |
+
if "All" in domain_en:
|
| 93 |
+
domain_en = ""
|
| 94 |
+
if domain_en:
|
| 95 |
+
for i in domain[:-1]:
|
| 96 |
+
sites_en = sites_en + "site:{} OR ".format(i)
|
| 97 |
+
sites_en = sites_en + "site:" + domain_en[-1]
|
| 98 |
+
|
| 99 |
+
query_en = keyword_en + " " + sites_en + " "
|
| 100 |
+
|
| 101 |
+
if keyword_en == "" and sites_en == "":
|
| 102 |
+
query = "Vaccine"
|
| 103 |
+
|
| 104 |
+
#-----------------------------------------------------------------------------------
|
| 105 |
+
if st.sidebar.button('Search 🔎'):
|
| 106 |
+
|
| 107 |
+
url_en = 'https://news.google.com/rss/search?q=' + quote(query_en) + 'when:1d&hl=en&gl=US'
|
| 108 |
+
#st.sidebar.write(url)
|
| 109 |
+
|
| 110 |
+
feed_en = feedparser.parse(url_en)
|
| 111 |
+
|
| 112 |
+
i = 1
|
| 113 |
+
html = ""
|
| 114 |
+
for post_en in feed_en.entries:
|
| 115 |
+
|
| 116 |
+
html = html + f"{post_en.title[:120]} <a href='{post_en.link}' target='_blank' > Link </a><br>"
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
if (i % 5 == 0):
|
| 120 |
+
html = html + "<br>"
|
| 121 |
+
i = i+1
|
| 122 |
+
|
| 123 |
+
html1 = f"""
|
| 124 |
+
<p style='font-size: 17px; font-family: Segoe UI;color:#202124'>
|
| 125 |
+
{html}
|
| 126 |
+
</p>
|
| 127 |
+
"""
|
| 128 |
+
st.markdown("<h2 style='text-align: center; font-family: Verdana; color: red;'>News 24h</h2><br>", unsafe_allow_html=True)
|
| 129 |
+
st.markdown(html1, unsafe_allow_html=True)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
#st.sidebar.title(url_en)
|