-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
48 lines (39 loc) · 1.27 KB
/
Copy pathdata.py
File metadata and controls
48 lines (39 loc) · 1.27 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
import json
import requests
from apms_config import API_KEY, BASE_URL, UP_KIND_DOG
def get_kinds(up_kind_cd: str = UP_KIND_DOG, num_of_rows: int = 300):
"""품종 목록 조회"""
url = f"{BASE_URL}/kind_v2"
params = {
"serviceKey": API_KEY,
"up_kind_cd": up_kind_cd,
"pageNo": 1,
"numOfRows": num_of_rows,
"_type": "json",
}
res = requests.get(url, params=params, timeout=30)
res.raise_for_status()
return res.json()
def get_abandoned_animals(page=1, num_of_rows=100):
"""구조동물 공고 조회"""
url = f"{BASE_URL}/abandonmentPublic_v2"
params = {
"serviceKey": API_KEY,
"pageNo": page,
"numOfRows": num_of_rows,
"_type": "json"
}
res = requests.get(url, params=params, timeout=30)
res.raise_for_status()
return res.json()
def main() -> None:
kinds = get_kinds()
with open("kinds_raw.json", "w", encoding="utf-8") as f:
json.dump(kinds, f, ensure_ascii=False, indent=2)
print("품종 조회 완료")
animals = get_abandoned_animals()
with open("animals_raw.json", "w", encoding="utf-8") as f:
json.dump(animals, f, ensure_ascii=False, indent=2)
print("공고 조회 완료")
if __name__ == "__main__":
main()