forked from dominhok/CodeWave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisaster_api.py
More file actions
53 lines (43 loc) Β· 1.75 KB
/
Copy pathdisaster_api.py
File metadata and controls
53 lines (43 loc) Β· 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
import urllib3
import os
from dotenv import load_dotenv
# .env νμΌ λ‘λ
load_dotenv()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
url = "https://www.safetydata.go.kr/V2/api/DSSP-IF-00247"
# νκ²½ λ³μμμ API ν€ λ‘λ
serviceKey = os.getenv("SAFETY_DATA_SERVICE_KEY")
# API ν€ λ‘λ νμΈ
if not serviceKey:
print("μ€λ₯: .env νμΌμμ SAFETY_DATA_SERVICE_KEY λ₯Ό μ°Ύμ μ μκ±°λ μ€μ λμ§ μμμ΅λλ€.")
exit() # ν€κ° μμΌλ©΄ μ€ν¬λ¦½νΈ μ’
λ£
params = {
"serviceKey": serviceKey,
"returnType": "json",
"pageNo": "1",
"numOfRows": "5",
"crtDt": "20250410", # μ€λ λ μ§ κΈ°μ€
}
print(f"Requesting data with Service Key starting with: {serviceKey[:5]}...") # ν€ μΌλΆλ§ λ‘κΉ
response = requests.get(url, params=params, verify=False)
print("Status Code:", response.status_code)
# μλ΅ μν νμΈ
if response.status_code == 200:
data = response.json()
print(data)
# λ°μ΄ν° ꡬ쑰 νμΈ ν νμ±
items = data.get("body", []) # body μλμ λ°λ‘ 리μ€νΈ μμ
for i, item in enumerate(items, 1):
print(f"\n[{i}]")
print("μΌλ ¨λ²νΈ:", item.get("SN", "μμ"))
print("μμ±μΌμ:", item.get("CRT_DT", "μμ"))
print("λ©μμ§λ΄μ©:", item.get("MSG_CN", "μμ"))
print("μμ μ§μλͺ
:", item.get("RCPTN_RGN_NM", "μμ"))
print("κΈ΄κΈλ¨κ³λͺ
:", item.get("EMRG_STEP_NM", "μμ"))
print("μ¬ν΄κ΅¬λΆλͺ
:", item.get("DST_SE_NM", "μμ"))
print("λ±λ‘μΌμ:", item.get("REG_YMD", "μμ"))
print("μμ μΌμ:", item.get("MDFCN_YMD", "μμ"))
else:
print("μμ² μ€ν¨:", response.status_code)
print("μλ΅ λ΄μ©:", response.text)