-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprf_api_caller.py
More file actions
77 lines (66 loc) · 2.87 KB
/
prf_api_caller.py
File metadata and controls
77 lines (66 loc) · 2.87 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import datetime
import os
from bs4 import BeautifulSoup
import requests
from prf_tools import *
class PrfCaller:
def __init__(self):
data = {}
self.service_key = os.environ['KOPIS_SERVICE_KEY']
def get_id_list(self, row, prfstate):
url = "http://kopis.or.kr/openApi/restful/pblprfr"
params = {
'service': self.service_key,
'cpage': 1,
'rows': row,
'prfstate': prfstate
}
response = requests.get(url, params=params).text
xmlobj = BeautifulSoup(response, 'lxml-xml')
list = [id.string for id in xmlobj.find_all("mt20id")]
return list
def get_performance(self, prf_id):
url = "http://kopis.or.kr/openApi/restful/pblprfr/{0}".format(prf_id)
params = {
'service': self.service_key
}
response = requests.get(url, params=params).text
xmlobj = BeautifulSoup(response, 'lxml-xml').find("db")
dtguidance = xmlobj.find("dtguidance").string
if dtguidance == ' ' or dtguidance == '':
return None
prf_ticket_price = xmlobj.find("pcseguidance").string
if prf_ticket_price == ' ' or prf_ticket_price == '':
return None
data = {}
data["performance_id"] = xmlobj.find("mt20id").string
data["facility_id"] = xmlobj.find("mt10id").string
data["prf_title"] = xmlobj.find("prfnm").string
data["prf_start_date"] = xmlobj.find(
"prfpdfrom").string.replace('.', '-')
data["prf_end_date"] = Validation().check_none(
xmlobj.find("prfpdto").string.replace('.', '-'))
data["prf_cast"] = Validation().check_none(
xmlobj.find("prfcast").string)
data["prf_crew"] = Validation().check_none(
xmlobj.find("prfcrew").string)
data["prf_runtime"] = Validation().check_none(
xmlobj.find("prfruntime").string)
data["prf_prd_comp"] = Validation().check_none(
xmlobj.find("entrpsnm").string)
data["prf_viewing_age"] = xmlobj.find("prfage").string
data["prf_ticket_price"] = Validation().check_none(
xmlobj.find("pcseguidance").string)
data["prf_poster"] = Validation().check_none(
xmlobj.find("poster").string)
data["prf_story"] = Validation(
).check_none(xmlobj.find("sty").string)
data["prf_genre"] = xmlobj.find("genrenm").string
data["prf_openrun"] = xmlobj.find("openrun").string
data["prf_styurls"] = Validation().check_none(
str(ParseToList().xml_to_list(xmlobj.findAll("styurl"))).replace("\'", "").replace("[","").replace("]","") )
data["prf_state"] = xmlobj.find("prfstate").string
data["prf_loaded_at"] = datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S')
data["dtguidance"] = xmlobj.find("dtguidance").string
return data