-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
68 lines (53 loc) · 2.09 KB
/
app.py
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
import streamlit as st
import datetime
from queries.query import query
import utils
import json
@st.cache_data
def get_items():
with open("data/url_items_all.json", "r") as f:
url_items = json.load(f)
for item in url_items:
item['relevance'] = int(item['relevance'])
item['date'] = utils.parse_date(item['date'])
# sort by relevance
url_items = sorted(url_items, key=lambda x: x['relevance'], reverse=True)
return url_items
today = datetime.datetime.now()
end = datetime.datetime(today.year, today.month, today.day)
start = end - datetime.timedelta(days=7)
url_items = get_items()
st.title('Дайджест новостей НЛМК')
category = st.selectbox('Категории', ['Все']+list(query.keys()))
d = st.date_input(
"Выберите отрезок времени",
(start, end),
format="MM.DD.YYYY",
)
if len(d) == 2:
d0, d1 = d
# convert to datetime
d0 = datetime.datetime.combine(d0, datetime.datetime.min.time())
d1 = datetime.datetime.combine(d1, datetime.datetime.min.time())
# filter by category
if category != 'Все':
url_items = [item for item in url_items if item['category'] == category]
# filter by date
url_items = [item for item in url_items if item['date'] is not None and d0 <= item['date'] <= d1]
# Improved display format for news items
for i, item in enumerate(url_items[:20]):
date = item['date']
if date is not None:
date = date.strftime('%d.%m.%Y')
summary = item['answer']['summary']
events = item['answer']['key_events']
if isinstance(events, list):
events = '\n - '.join(events)
st.markdown(f"#### \#{i+1} **{item['title']}**")
st.markdown(f"*{item['category']}* | *{date}*")
st.markdown(f"**Summary:** {summary}")
st.markdown(f"**Events:** \n{events}")
web_url = '/'.join(item['url'].split('/')[:3])
st.markdown(f"Полная версия: [{web_url}]({item['url']})")
st.markdown(f"**Relevance:** {item['relevance']}")
st.write('---')