JAMESPARK3 commited on
Commit
90b9979
ยท
verified ยท
1 Parent(s): 2db051a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -199,28 +199,39 @@ def check_network_status():
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:
223
- st.error(f"๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {e}")
224
  return None
225
 
226
  def get_background_color(pm10_value):
 
199
  except httpx.RequestError:
200
  return False
201
 
202
+ @st.cache_data(ttl=300)
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, timeout=10) # timeout ์ถ”๊ฐ€
207
+ response.raise_for_status()
208
+
209
+ # ์‘๋‹ต ๋‚ด์šฉ ๋””๋ฒ„๊น…
210
+ st.write("Status Code:", response.status_code)
211
+ st.write("Response Headers:", dict(response.headers))
212
+
213
+ response_text = response.text.strip()
214
+ if not response_text:
215
  st.error("์‘๋‹ต์ด ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค.")
216
  return None
217
+
218
+ # XML ํŒŒ์‹ฑ ์ „ ์‘๋‹ต ํ™•์ธ
219
+ st.write("Raw Response:", response_text[:200]) # ์ฒ˜์Œ 200์ž๋งŒ ์ถœ๋ ฅ
220
+
221
  data = xmltodict.parse(response_text)
222
+ result = data['SeoulRtd.citydata']['CITYDATA']['WEATHER_STTS']['WEATHER_STTS']
223
+
224
+ # ํŒŒ์‹ฑ๋œ ๋ฐ์ดํ„ฐ ํ™•์ธ
225
+ st.write("Parsed Data:", result)
226
+
227
+ return result
228
 
229
+ except requests.exceptions.Timeout:
230
+ st.error("API ์š”์ฒญ ์‹œ๊ฐ„์ด ์ดˆ๊ณผ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
231
  except requests.exceptions.RequestException as e:
232
+ st.error(f"API ํ˜ธ์ถœ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
233
  except Exception as e:
234
+ st.error(f"๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
235
  return None
236
 
237
  def get_background_color(pm10_value):