- 论坛徽章:
- 0
|
本帖最后由 two_cu 于 2010-10-07 19:27 编辑
- #! /usr/bin/python
- # -*- coding: utf-8 -*-
- import urllib,re,unicodedata,string,sys
- from time import strftime,localtime
- channel={"1":"CCTV1","2":"CCTV2","3":"CCTV3","4":"CCTV4",
- "5":"CCTV5","6":"CCTV6","7":"CCTV7","8":"CCTV8",
- "9":"CCTV9","10":"CCTV10","11":"CCTV11","12":"CCTV12",
- "13":"cctv13","Asia":"cctvAsia","Europe":"cctvEurope","Americas":"cctvAmericas",
- "Children":"cctvChildren","Music":"cctvMusic","E":"cctvE","F":"cctvF",
- "Arabic":"cctvAragic","Russian":"Russian","Gaoqing":"cctvGaoqing"}
- if __name__=="__main__":
- if len(sys.argv)==1:
- Select="6"
- else:
- if sys.argv[1] not in channel.keys():
- print "Out of Range. Please Select The following option:"
- keylist=channel.keys()
- keylist.sort()
- for i in keylist:
- print "%-9s: %-30s" %(i,channel[i])
- sys.exit(0)
- else:
- Select=sys.argv[1]
- print '正在获取节目单,请稍后...'
- date=strftime('%Y%m%d',localtime())
- response = urllib.urlopen("http://bugu.cntv.cn/nettv/ibugu/28/"+channel[Select]+"/"+date+".shtml")
- Result=response.read()
- listP=re.findall(r"上午节目(.+?)<!--.subbar-->",Result,re.S)
- list=re.findall(r"<table(.+?)</table>",listP[0],re.S)
- list_AM=re.findall(r'<td width="19%">(.+?)</td>',list[0],re.S)
- list_AM_prog=re.findall(r'<td width="66%">(.+?)</td>',list[0],re.S)
- list_PM=re.findall(r"<td width='19%'>(.+?)</td>",list[1],re.S)
- list_PM_prog=re.findall(r"<td width='66%'>(.+?)</td>",list[1],re.S)
- #listnum=0
- if len(list_AM)>len(list_PM):
- listnum=len(list_AM)
- else:
- listnum=len(list_PM)
- print "-"*80,
- print " "*13+"上午节目"+" "*26+"下午节目"
- print " "*14+"========"+" "*26+"========"
- for i in range(listnum):
- if(i<len(list_AM)):
- print "%-4s %-29s" %(list_AM[i],list_AM_prog[i][:28]),
- else:
- print " "*35,
- if(i<len(list_PM)):
- print "%-4s %-30s" %(list_PM[i],list_PM_prog[i][:28])
- else:
- print " "*37
- print "-"*80,
- print " "*24,strftime("%Y年%m月%d日"),
- print "%s 节目单" %channel[Select]
复制代码 |
评分
-
查看全部评分
|