JAMESPARK3 commited on
Commit
6d63095
ยท
verified ยท
1 Parent(s): 2dc832f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -14
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
- 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,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
- 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,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()