Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -162,12 +162,32 @@ def filter_variable_options(df):
|
|
| 162 |
github_token = st.secrets["GitHub_Token_KUL_Margarida"]
|
| 163 |
#countries = ['IT_CALA', 'IT_CNOR', 'IT_CSUD', 'IT_SARD', 'PT', 'FR']
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
| 167 |
for bdz in countries:
|
| 168 |
df = load_GitHub(github_token, bdz)
|
| 169 |
if df is not None:
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
else:
|
| 173 |
print("Please enter your GitHub Personal Access Token to proceed.")
|
|
|
|
| 162 |
github_token = st.secrets["GitHub_Token_KUL_Margarida"]
|
| 163 |
#countries = ['IT_CALA', 'IT_CNOR', 'IT_CSUD', 'IT_SARD', 'PT', 'FR']
|
| 164 |
|
| 165 |
+
@st.cache_data(show_spinner=False)
|
| 166 |
+
def load_all_from_github(github_token, countries, period_key):
|
| 167 |
+
"""Fetch all zones’ CSVs from GitHub and return as dict."""
|
| 168 |
+
data = {}
|
| 169 |
for bdz in countries:
|
| 170 |
df = load_GitHub(github_token, bdz)
|
| 171 |
if df is not None:
|
| 172 |
+
data[bdz] = df
|
| 173 |
+
return data
|
| 174 |
+
|
| 175 |
+
# in your main script, _before_ you do the for-loop
|
| 176 |
+
now = datetime.now(tz)
|
| 177 |
+
|
| 178 |
+
if now.minute >= 15:
|
| 179 |
+
block_start = now.replace(minute=0, second=0, microsecond=0)
|
| 180 |
+
else:
|
| 181 |
+
block_start = (now - timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
|
| 182 |
+
|
| 183 |
+
# turn it into a simple string key
|
| 184 |
+
period_key = block_start.strftime("%Y-%m-%d-%H")
|
| 185 |
+
|
| 186 |
+
if github_token:
|
| 187 |
+
data_dict = load_all_from_github(github_token, countries, period_key)
|
| 188 |
+
else:
|
| 189 |
+
st.error("Please enter your GitHub Personal Access Token to proceed.")
|
| 190 |
+
st.stop()
|
| 191 |
|
| 192 |
else:
|
| 193 |
print("Please enter your GitHub Personal Access Token to proceed.")
|