KT 함수 수정

This commit is contained in:
wonipapa 2017-10-10 11:50:35 +09:00
parent bb7697fdf8
commit 2beb41b715

View File

@ -56,7 +56,6 @@ SOCKET_ERROR = 'xmltv.sock 파일을 찾을 수 없습니다.'
JSON_FILE_ERROR = 'json 파일을 읽을 수 없습니다.' JSON_FILE_ERROR = 'json 파일을 읽을 수 없습니다.'
JSON_SYNTAX_ERROR = 'json 파일 형식이 잘못되었습니다.' JSON_SYNTAX_ERROR = 'json 파일 형식이 잘못되었습니다.'
# Get epg data # Get epg data
def getEpg(): def getEpg():
Channelfile = os.path.dirname(os.path.abspath(__file__)) + '/Channel.json' Channelfile = os.path.dirname(os.path.abspath(__file__)) + '/Channel.json'
@ -220,35 +219,34 @@ def GetEPGFromKT(ChannelInfo):
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]
ServiceId = ChannelInfo[3] ServiceId = ChannelInfo[3]
epginfo = [] epginfo = []
url = 'http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp' url = 'http://tv.kt.com/tv/channel/pSchedule.asp'
for k in range(period): for k in range(period):
day = today + datetime.timedelta(days=k) day = today + datetime.timedelta(days=k)
params = {'ch_name':'', 'ch_no':ServiceId, 'nowdate':day.strftime('%Y%m%d'), 'seldatie':day.strftime('%Y%m%d'), 'tab_no':'1'} params = {'ch_type':'1', 'view_type':'1', 'service_ch_no':ServiceId, 'seldate':day.strftime('%Y%m%d')}
try: try:
response = requests.get(url, params=params, headers=ua, timeout=timeout) response = requests.post(url, data=params, headers=ua, timeout=timeout)
response.raise_for_status() response.raise_for_status()
html_data = response.content html_data = response.content
data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore') data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
strainer = SoupStrainer('table', {'id':'pop_day'}) strainer = SoupStrainer('tbody')
soup = BeautifulSoup(data, htmlparser, parse_only=strainer, from_encoding='utf-8') soup = BeautifulSoup(data, htmlparser, parse_only=strainer, from_encoding='utf-8')
html = soup.find('table', {'id':'pop_day'}).tbody.find_all('tr') if soup.find('table', {'id':'pop_day'}) else '' html = soup.find_all('tr') if soup.find('tbody') else ''
if(html): if(html):
for row in html: for row in html:
for cell in [row.find_all('td')]: for cell in [row.find_all('td')]:
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = '' startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
rebroadcast = False rebroadcast = False
rating = 0 rating = 0
startTime = str(day) + ' ' + cell[0].text for minute, program, cateogry in zip(cell[1].find_all('p'), cell[2].find_all('p'), cell[3].find_all('p')):
startTime = str(day) + ' ' + cell[0].text.strip() + ':' + minute.text.strip()
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M') startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
startTime = startTime.strftime('%Y%m%d%H%M%S') startTime = startTime.strftime('%Y%m%d%H%M%S')
pattern = '^(.*?)( <(.*)>)?$' programName = program.text.strip()
matches = re.match(pattern, cell[1].text.decode('string_escape')) cateogry = cateogry.text.strip()
if not (matches is None): for image in [program.find_all('img', alt=True)]:
programName = matches.group(1) if matches.group(1) else '' rating = 0
subprogramName = matches.group(3) if matches.group(3) else '' grade = re.match('([\d,]+)',image[0]['alt'])
category = cell[4].text if not (grade is None): rating = int(grade.group(1))
matches = re.match('(\d+)', cell[2].text)
if not(matches is None): rating = int(matches.group())
#ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating #ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating]) epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating])
time.sleep(0.001) time.sleep(0.001)
@ -1079,6 +1077,7 @@ try:
Settings = json.load(f) Settings = json.load(f)
MyISP = Settings['MyISP'] if 'MyISP' in Settings else 'ALL' MyISP = Settings['MyISP'] if 'MyISP' in Settings else 'ALL'
MyChannels = Settings['MyChannels'] if 'MyChannels' in Settings else '' MyChannels = Settings['MyChannels'] if 'MyChannels' in Settings else ''
MergeChannels = Settings['MergeChannels'] if 'MergeChannels' in Settings else ''
default_output = Settings['output'] if 'output' in Settings else 'd' default_output = Settings['output'] if 'output' in Settings else 'd'
default_xml_file = Settings['default_xml_file'] if 'default_xml_file' in Settings else 'xmltv.xml' default_xml_file = Settings['default_xml_file'] if 'default_xml_file' in Settings else 'xmltv.xml'
default_xml_socket = Settings['default_xml_socket'] if 'default_xml_socket' in Settings else 'xmltv.sock' default_xml_socket = Settings['default_xml_socket'] if 'default_xml_socket' in Settings else 'xmltv.sock'