정지 시간 추가
This commit is contained in:
parent
d83851b4fa
commit
431d23c7d9
98
epg2xml.py
98
epg2xml.py
@ -16,7 +16,7 @@ import argparse
|
|||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf-8')
|
sys.setdefaultencoding('utf-8')
|
||||||
|
|
||||||
__version__ = '1.0.7'
|
__version__ = '1.0.8'
|
||||||
|
|
||||||
# Set My Configuration
|
# Set My Configuration
|
||||||
default_icon_url = '' # TV channel icon url (ex : http://www.example.com/Channels)
|
default_icon_url = '' # TV channel icon url (ex : http://www.example.com/Channels)
|
||||||
@ -97,6 +97,7 @@ def GetEPGFromEPG(ChannelInfo):
|
|||||||
ChannelId = ChannelInfo[0]
|
ChannelId = ChannelInfo[0]
|
||||||
ChannelName = ChannelInfo[1]
|
ChannelName = ChannelInfo[1]
|
||||||
ServiceId = ChannelInfo[3]
|
ServiceId = ChannelInfo[3]
|
||||||
|
epginfo = []
|
||||||
url = 'http://www.epg.co.kr/epg-cgi/extern/cnm_guide_type_v070530.cgi'
|
url = 'http://www.epg.co.kr/epg-cgi/extern/cnm_guide_type_v070530.cgi'
|
||||||
contenturl = 'http://www.epg.co.kr/epg-cgi/guide_schedule_content.cgi'
|
contenturl = 'http://www.epg.co.kr/epg-cgi/guide_schedule_content.cgi'
|
||||||
for k in range(period):
|
for k in range(period):
|
||||||
@ -113,7 +114,6 @@ def GetEPGFromEPG(ChannelInfo):
|
|||||||
|
|
||||||
for i in range(1,4):
|
for i in range(1,4):
|
||||||
thisday = day
|
thisday = day
|
||||||
pid = ''
|
|
||||||
row = table[i].find_all('td', {'colspan':'2'})
|
row = table[i].find_all('td', {'colspan':'2'})
|
||||||
for j, cell in enumerate(row):
|
for j, cell in enumerate(row):
|
||||||
hour = int(cell.text.strip().strip('시'))
|
hour = int(cell.text.strip().strip('시'))
|
||||||
@ -124,50 +124,37 @@ def GetEPGFromEPG(ChannelInfo):
|
|||||||
hour = 'AM ' + str(hour)
|
hour = 'AM ' + str(hour)
|
||||||
thisday = day + datetime.timedelta(days=1)
|
thisday = day + datetime.timedelta(days=1)
|
||||||
for celldata in cell.parent.find_all('tr'):
|
for celldata in cell.parent.find_all('tr'):
|
||||||
matches = re.match("<tr>.*\[(.*)\]<\/td>\s.*ViewContent\('(.*)'\)\">(.*?)\s*(<(.*)>)?\s*(\(재\))?\s*(\(([\d,]+)회\))?(<img.*)?<\/a> <\/td><\/tr>", str(celldata))
|
pattern = "<tr>.*\[(.*)\]<\/td>\s.*\">(.*?)\s*(<(.*)>)?\s*(\(재\))?\s*(\(([\d,]+)회\))?(<img.*?)?(<\/a>)?\s*<\/td><\/tr>"
|
||||||
|
matches = re.match(pattern, str(celldata))
|
||||||
if not (matches is None):
|
if not (matches is None):
|
||||||
minute = matches.group(1) if matches.group(1) else ''
|
minute = matches.group(1) if matches.group(1) else ''
|
||||||
startTime = str(thisday) + ' ' + hour + ':' + minute
|
startTime = str(thisday) + ' ' + hour + ':' + minute
|
||||||
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %p %I:%M')
|
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %p %I:%M')
|
||||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||||
endTime = ''
|
image = matches.group(8) if matches.group(8) else ''
|
||||||
pid = matches.group(2) if matches.group(2) else ''
|
grade = re.match('.*schedule_([\d,]+)?.*',image)
|
||||||
programName = matches.group(3) if matches.group(3) else ''
|
if not (grade is None): rating = int(grade.group(1))
|
||||||
subprogramName = matches.group(5) if matches.group(5) else ''
|
else : rating = 0
|
||||||
|
#programName, startTime, rating, subprogramName, rebroadcast, episode
|
||||||
|
epginfo.append([matches.group(2), startTime, rating, matches.group(4), matches.group(5), matches.group(7)])
|
||||||
|
|
||||||
|
for epg1, epg2 in zip(epginfo, epginfo[1:]):
|
||||||
|
programName = epg1[0] if epg1[0] else ''
|
||||||
|
subprogramName = epg1[3] if epg1[3] else ''
|
||||||
|
startTime = epg1[1] if epg1[1] else ''
|
||||||
|
endTime = epg2[1] if epg2[1] else ''
|
||||||
desc = ''
|
desc = ''
|
||||||
actors = ''
|
actors = ''
|
||||||
producers = ''
|
producers = ''
|
||||||
category = ''
|
category = ''
|
||||||
rebroadcast = True if matches.group(6) else False
|
rebroadcast = True if epg1[4] else False
|
||||||
episode = matches.group(8) if matches.group(8) else ''
|
episode = epg1[5] if epg1[5] else ''
|
||||||
image = matches.group(9) if matches.group(9) else ''
|
rating = int(epg1[2]) if epg1[2] else 0
|
||||||
grade = re.match('.*schedule_([\d,]+)?.*',image)
|
|
||||||
if not (grade is None):
|
|
||||||
rating = int(grade.group(1))
|
|
||||||
else :
|
|
||||||
rating = 0
|
|
||||||
if(i == 3 and len(row) - 1 == j and pid) :
|
|
||||||
params = {'pid':pid}
|
|
||||||
try:
|
|
||||||
response = requests.get(contenturl, params=params, headers=ua)
|
|
||||||
response.raise_for_status()
|
|
||||||
html_data = response.content
|
|
||||||
data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
|
||||||
strainer = SoupStrainer('table', {'border':'0', 'cellpadding':'3'})
|
|
||||||
soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
|
|
||||||
td = soup.select('tr:nth-of-type(3) > td:nth-of-type(3)')
|
|
||||||
endTime = td[0].text.split('~')[1].replace('시',':').replace('분','').replace(': ', ':').strip()
|
|
||||||
if(endTime.startswith('0')): endTime = endTime.replace('0:','12:')
|
|
||||||
endTime = str(thisday) + ' ' + 'AM ' + endTime
|
|
||||||
if(endTime.endswith(':')) : endTime = endTime + '00'
|
|
||||||
endTime = datetime.datetime.strptime(endTime, '%Y-%m-%d %p %I:%M')
|
|
||||||
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
|
||||||
except requests.exceptions.HTTPError:
|
|
||||||
printError(ChannelName + HTTP_ERROR)
|
|
||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
# Get EPG data from KT
|
# Get EPG data from KT
|
||||||
def GetEPGFromKT(ChannelInfo):
|
def GetEPGFromKT(ChannelInfo):
|
||||||
@ -215,9 +202,12 @@ def GetEPGFromKT(ChannelInfo):
|
|||||||
if not(matches is None): rating = int(matches.group())
|
if not(matches is None): rating = int(matches.group())
|
||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
else: printError(ChannelName + CONTENT_ERROR)
|
else:
|
||||||
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
# Get EPG data from LG
|
# Get EPG data from LG
|
||||||
def GetEPGFromLG(ChannelInfo):
|
def GetEPGFromLG(ChannelInfo):
|
||||||
@ -249,17 +239,12 @@ def GetEPGFromLG(ChannelInfo):
|
|||||||
matches = re.match('^(.*?)(\(([\d,]+)회\))?$', epg1[0].decode('string_escape'))
|
matches = re.match('^(.*?)(\(([\d,]+)회\))?$', epg1[0].decode('string_escape'))
|
||||||
if not (matches is None):
|
if not (matches is None):
|
||||||
programName = matches.group(1) if matches.group(1) else ''
|
programName = matches.group(1) if matches.group(1) else ''
|
||||||
episode = int(matches.group(3)) if matches.group(3) else ''
|
episode = matches.group(3) if matches.group(3) else ''
|
||||||
startTime = datetime.datetime.strptime(epg1[1], '%Y-%m-%d %H:%M')
|
startTime = datetime.datetime.strptime(epg1[1], '%Y-%m-%d %H:%M')
|
||||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||||
endTime = datetime.datetime.strptime(epg2[1], '%Y-%m-%d %H:%M')
|
endTime = datetime.datetime.strptime(epg2[1], '%Y-%m-%d %H:%M')
|
||||||
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
||||||
category = epg1[2]
|
category = epg1[2]
|
||||||
if verbose=='y' :
|
|
||||||
desc = ''
|
|
||||||
actors = epgdata[6]
|
|
||||||
producers = epgdata[7]
|
|
||||||
else:
|
|
||||||
desc = ''
|
desc = ''
|
||||||
actors = ''
|
actors = ''
|
||||||
producers = ''
|
producers = ''
|
||||||
@ -269,9 +254,12 @@ def GetEPGFromLG(ChannelInfo):
|
|||||||
if not(matches is None): rating = int(matches.group(1))
|
if not(matches is None): rating = int(matches.group(1))
|
||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
else: printError(ChannelName + CONTENT_ERROR)
|
else:
|
||||||
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
# Get EPG data from SK
|
# Get EPG data from SK
|
||||||
def GetEPGFromSK(ChannelInfo):
|
def GetEPGFromSK(ChannelInfo):
|
||||||
@ -321,9 +309,11 @@ def GetEPGFromSK(ChannelInfo):
|
|||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
printError(ChannelName + CONTENT_ERROR)
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
# Get EPG data from SKY
|
# Get EPG data from SKY
|
||||||
def GetEPGFromSKY(ChannelInfo):
|
def GetEPGFromSKY(ChannelInfo):
|
||||||
@ -341,7 +331,8 @@ def GetEPGFromSKY(ChannelInfo):
|
|||||||
try:
|
try:
|
||||||
data = json.loads(json_data, encoding='utf-8')
|
data = json.loads(json_data, encoding='utf-8')
|
||||||
if (len(data['scheduleListIn']) == 0) :
|
if (len(data['scheduleListIn']) == 0) :
|
||||||
printError(ChannelName + CONTENT_ERROR)
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
else :
|
else :
|
||||||
programs = data['scheduleListIn']
|
programs = data['scheduleListIn']
|
||||||
for program in {v['starttime']:v for v in programs}.values():
|
for program in {v['starttime']:v for v in programs}.values():
|
||||||
@ -370,9 +361,11 @@ def GetEPGFromSKY(ChannelInfo):
|
|||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
printError(ChannelName + CONTENT_ERROR)
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
# Get EPG data from Naver
|
# Get EPG data from Naver
|
||||||
def GetEPGFromNaver(ChannelInfo):
|
def GetEPGFromNaver(ChannelInfo):
|
||||||
@ -417,9 +410,11 @@ def GetEPGFromNaver(ChannelInfo):
|
|||||||
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
programdata = {'channelId':ChannelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rebroadcast':rebroadcast, 'rating':rating}
|
||||||
writeProgram(programdata)
|
writeProgram(programdata)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
printError(ChannelName + CONTENT_ERROR)
|
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||||
|
else: pass
|
||||||
except requests.exceptions.HTTPError:
|
except requests.exceptions.HTTPError:
|
||||||
printError(ChannelName + HTTP_ERROR)
|
if(debug): printError(ChannelName + HTTP_ERROR)
|
||||||
|
else: pass
|
||||||
|
|
||||||
|
|
||||||
# Write Program
|
# Write Program
|
||||||
@ -536,3 +531,4 @@ elif args.socket:
|
|||||||
sys.stdout = sockfile
|
sys.stdout = sockfile
|
||||||
|
|
||||||
getEpg()
|
getEpg()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user