Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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)
|
| 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()
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
st.write("
|
| 212 |
-
|
| 213 |
-
|
|
|
|
| 214 |
st.error("์๋ต์ด ๋น์ด ์์ต๋๋ค.")
|
| 215 |
return None
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
| 217 |
data = xmltodict.parse(response_text)
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
|
|
|
|
|
|
| 220 |
except requests.exceptions.RequestException as e:
|
| 221 |
-
st.error(f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
| 222 |
except Exception as e:
|
| 223 |
-
st.error(f"๋ฐ์ดํฐ
|
| 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):
|