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,6 +161,20 @@ st.markdown("""
|
|
| 161 |
0% {transform: translateX(100%);}
|
| 162 |
100% {transform: translateX(-100%);}
|
| 163 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
</style>
|
| 165 |
""", unsafe_allow_html=True)
|
| 166 |
|
|
@@ -178,16 +192,31 @@ def get_korean_weekday(date):
|
|
| 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 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,16 +758,19 @@ def main():
|
|
| 729 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ placeholder
|
| 730 |
refresh_placeholder = st.empty()
|
| 731 |
|
| 732 |
-
#
|
| 733 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
|
|
|
|
|
|
|
|
|
| 742 |
|
| 743 |
data = st.session_state.weather_data
|
| 744 |
if data:
|
|
@@ -766,4 +798,4 @@ def main():
|
|
| 766 |
st.rerun()
|
| 767 |
|
| 768 |
if __name__ == "__main__":
|
| 769 |
-
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 |
+
|
| 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 |
}
|
| 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 |
+
response_text = response.text.strip() # ์๋ต ํ
์คํธ๋ฅผ ์คํธ๋ฆฝํ์ฌ ๊ธฐ๋ก
|
| 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 |
# ์๋ ์๋ก๊ณ ์นจ์ ์ํ placeholder
|
| 759 |
refresh_placeholder = st.empty()
|
| 760 |
|
| 761 |
+
# ๋คํธ์ํฌ ์ํ ์ฒดํฌ ๋ฐ ๋ฐ์ดํฐ ๊ฐฑ์
|
| 762 |
if not st.session_state.weather_data or time_since_last_call >= 300:
|
| 763 |
+
if check_network_status(): # ๋คํธ์ํฌ๊ฐ ์ ์์ธ ๊ฒฝ์ฐ๋ง API ํธ์ถ
|
| 764 |
+
try:
|
| 765 |
+
new_data = get_weather_data()
|
| 766 |
+
if new_data: # ์ ๋ฐ์ดํฐ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๋ฐ์์์ ๋๋ง ์
๋ฐ์ดํธ
|
| 767 |
+
st.session_state.weather_data = new_data
|
| 768 |
+
st.session_state.last_api_call = current_timestamp
|
| 769 |
+
st.rerun() # ํ์ด์ง ์๋ก๊ณ ์นจ
|
| 770 |
+
except Exception as e:
|
| 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 |
st.rerun()
|
| 799 |
|
| 800 |
if __name__ == "__main__":
|
| 801 |
+
main()
|