Code snippet:
import streamlit as st
from bs4 import BeautifulSoup
import pandas as pd
import datetime
import requests
from streamlit_lottie import st_lottie,st_lottie_spinner
import altair as alt
now = datetime.datetime.now()
if 6 < now.hour < 24:
next_day_6am = now.replace(hour=6, minute=0, second=0, microsecond=0) + datetime.timedelta(days=1)
else :
next_day_6am = now.replace(hour=6, minute=0, second=0, microsecond=0)
time_remaining = (next_day_6am - now).seconds
time_remaining = float(time_remaining)
@st.experimental_singleton(ttl=time_remaining)
def trade(city, date):
url = 'http://~~~'
xml = requests.get(url)
result = xml.text
soup = BeautifulSoup(result, 'lxml-xml')
items = soup.findAll("item")
aptTrade = pd.DataFrame()
(omission...)
return aptTrade
Hello.
I have a question.
There is an API where the database is updated at 6 a.m. every morning.
I need to set the effective time of the ttl option to keep the cache valid in order to show new data to the user.
I saw in the document that ttl needs to enter a float or date time.
I expected that the cache would remain for the entered time if the time remaining until 6 a.m. the next day was converted into seconds based on when the application was run.
However, the cache did not work when reloading.
Therefore, it took a long time to load the data each time.
What is the error in my code?
Thanks.