Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ st.set_page_config(
|
|
25 |
}
|
26 |
)
|
27 |
|
28 |
-
# CSS ์คํ์ผ
|
29 |
st.markdown("""
|
30 |
<style>
|
31 |
section[data-testid="stSidebar"] {
|
@@ -161,20 +161,6 @@ st.markdown("""
|
|
161 |
0% {transform: translateX(100%);}
|
162 |
100% {transform: translateX(-100%);}
|
163 |
}
|
164 |
-
|
165 |
-
/* ๋ชจ๋ฐ์ผ ๋์์ ์ํ CSS ์ถ๊ฐ */
|
166 |
-
@media (max-width: 600px) {
|
167 |
-
.time-container {
|
168 |
-
font-size: 3em; /* ์ค์ */
|
169 |
-
}
|
170 |
-
.date-text {
|
171 |
-
font-size: 4em !important; /* ์ค์ */
|
172 |
-
}
|
173 |
-
|
174 |
-
.scroll-text {
|
175 |
-
font-size: 1.2em; /* ํฐํธ ํฌ๊ธฐ ์ค์ */
|
176 |
-
}
|
177 |
-
}
|
178 |
</style>
|
179 |
""", unsafe_allow_html=True)
|
180 |
|
@@ -192,31 +178,16 @@ def get_korean_weekday(date):
|
|
192 |
}
|
193 |
return weekday_dict[weekday]
|
194 |
|
195 |
-
def check_network_status():
|
196 |
-
try:
|
197 |
-
response = httpx.get("http://www.google.com", timeout=5)
|
198 |
-
return response.status_code == 200
|
199 |
-
except httpx.RequestError:
|
200 |
-
return False
|
201 |
-
|
202 |
@st.cache_data(ttl=300) # 5๋ถ๋ง๋ค ์บ์ ๊ฐฑ์
|
203 |
def get_weather_data():
|
204 |
url = "http://openapi.seoul.go.kr:8088/77544e69764a414d363647424a655a/xml/citydata/1/5/์ ๋ฆผ์ญ"
|
205 |
try:
|
206 |
response = requests.get(url)
|
207 |
response.raise_for_status() # HTTPError์ ๋ํด ์์ธ ๋ฐ์
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
st.write("API ์๋ต ๋ด์ฉ:", response_text) # ๋๋ฒ๊ทธ ๋ก๊ทธ์ ์์ ์๋ต ์ถ๋ ฅ
|
212 |
-
|
213 |
-
if not response_text: # ๋น ์๋ต ์ฒ๋ฆฌ
|
214 |
-
st.error("์๋ต์ด ๋น์ด ์์ต๋๋ค.")
|
215 |
-
return None
|
216 |
-
|
217 |
-
data = xmltodict.parse(response_text)
|
218 |
return data['SeoulRtd.citydata']['CITYDATA']['WEATHER_STTS']['WEATHER_STTS']
|
219 |
-
|
220 |
except requests.exceptions.RequestException as e:
|
221 |
st.error(f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
222 |
except Exception as e:
|
@@ -758,19 +729,16 @@ def main():
|
|
758 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ placeholder
|
759 |
refresh_placeholder = st.empty()
|
760 |
|
761 |
-
#
|
762 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
st.error(f"Failed to refresh data: {str(e)}")
|
772 |
-
else:
|
773 |
-
st.warning("ํ์ฌ ๋คํธ์ํฌ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ฐ์ดํฐ ๊ฐฑ์ ์ด ๋ถ๊ฐ๋ฅํฉ๋๋ค.")
|
774 |
|
775 |
data = st.session_state.weather_data
|
776 |
if data:
|
@@ -798,4 +766,4 @@ def main():
|
|
798 |
st.rerun()
|
799 |
|
800 |
if __name__ == "__main__":
|
801 |
-
main()
|
|
|
25 |
}
|
26 |
)
|
27 |
|
28 |
+
# CSS ์คํ์ผ
|
29 |
st.markdown("""
|
30 |
<style>
|
31 |
section[data-testid="stSidebar"] {
|
|
|
161 |
0% {transform: translateX(100%);}
|
162 |
100% {transform: translateX(-100%);}
|
163 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
</style>
|
165 |
""", unsafe_allow_html=True)
|
166 |
|
|
|
178 |
}
|
179 |
return weekday_dict[weekday]
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
@st.cache_data(ttl=300) # 5๋ถ๋ง๋ค ์บ์ ๊ฐฑ์
|
182 |
def get_weather_data():
|
183 |
url = "http://openapi.seoul.go.kr:8088/77544e69764a414d363647424a655a/xml/citydata/1/5/์ ๋ฆผ์ญ"
|
184 |
try:
|
185 |
response = requests.get(url)
|
186 |
response.raise_for_status() # HTTPError์ ๋ํด ์์ธ ๋ฐ์
|
187 |
+
if not response.text.strip(): # ๋น ์๋ต ์ฒ๋ฆฌ
|
188 |
+
raise ValueError("์๋ต์ด ๋น์ด ์์ต๋๋ค.")
|
189 |
+
data = xmltodict.parse(response.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
return data['SeoulRtd.citydata']['CITYDATA']['WEATHER_STTS']['WEATHER_STTS']
|
|
|
191 |
except requests.exceptions.RequestException as e:
|
192 |
st.error(f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
193 |
except Exception as e:
|
|
|
729 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ placeholder
|
730 |
refresh_placeholder = st.empty()
|
731 |
|
732 |
+
# ๋ฐ์ดํฐ ๊ฐฑ์ ์ด ํ์ํ ๊ฒฝ์ฐ
|
733 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
734 |
+
try:
|
735 |
+
new_data = get_weather_data()
|
736 |
+
if new_data: # ์ ๋ฐ์ดํฐ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๋ฐ์์์ ๋๋ง ์
๋ฐ์ดํธ
|
737 |
+
st.session_state.weather_data = new_data
|
738 |
+
st.session_state.last_api_call = current_timestamp
|
739 |
+
st.rerun() # ํ์ด์ง ์๋ก๊ณ ์นจ
|
740 |
+
except Exception as e:
|
741 |
+
st.error(f"Failed to refresh data: {str(e)}")
|
|
|
|
|
|
|
742 |
|
743 |
data = st.session_state.weather_data
|
744 |
if data:
|
|
|
766 |
st.rerun()
|
767 |
|
768 |
if __name__ == "__main__":
|
769 |
+
main()
|