-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfclty_api_caller.py
48 lines (38 loc) · 1.47 KB
/
fclty_api_caller.py
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 os
from fclty_tools import *
import requests
from bs4 import BeautifulSoup
class FcltyCaller:
def __init__(self):
data = {}
self.service_key = os.environ['KOPIS_SERVICE_KEY']
def get_id_list(self, row):
url = "http://www.kopis.or.kr/openApi/restful/prfplc"
params = {
'service': self.service_key,
'cpage': 1,
'rows': row
}
response = requests.get(url, params=params).text
xmlobj = BeautifulSoup(response, 'lxml-xml')
list = [id.string for id in xmlobj.find_all("mt10id")]
return list
def get_facility(self, fclty_id):
url = "http://www.kopis.or.kr/openApi/restful/prfplc/{0}".format(
fclty_id)
params = {
'service': self.service_key
}
response = requests.get(url, params=params).text
xmlobj = BeautifulSoup(response, 'lxml-xml').find("db")
data = {}
data["facility_id"] = xmlobj.find("mt10id").string
data["facility_name"] = xmlobj.find("fcltynm").string
data["facility_telno"] = Validation().check_none(
xmlobj.find("telno").string)
data["facility_relateurl"] = Validation().check_none(
xmlobj.find("relateurl").string)
data["facility_address"] = xmlobj.find("adres").string
data["facility_latitude"] = float(xmlobj.find("la").string)
data["facility_longitude"] = float(xmlobj.find("lo").string)
return data