-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
25 lines (22 loc) · 1.09 KB
/
utils.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
import json
import streamlit as st
from functional import SummaryContent, SearchEngine
@st.cache_data
def search(keys="", period='1d', news_num=1):
st.session_state["search_engine"].clear()
st.session_state["search_engine"].set_period(period)
results = st.session_state["search_engine"].search(keys=keys, nums=news_num)
# results = [SummaryContent(news=r, engine=st.session_state["search_engine"]) for r in results]
return json.dumps({"results": results})
@st.cache_data
def form_summarycontent(raw_data={}):
raw_data = json.loads(raw_data)
# st.session_state["raw_contents"] = search(keys=st.session_state["current_search"], news_num=10)
st.session_state["raw_contents"] = raw_data["results"]#json.loads(st.session_state["raw_contents"])["results"]
st.session_state["contents"] = [SummaryContent(news=r, engine=SearchEngine(lang="en", region="US")) for r in st.session_state["raw_contents"]]
def clear():
st.session_state["current_search"] = ""
st.session_state["raw_contents"] = []
st.session_state["contents"] = []
search.clear()
form_summarycontent.clear()