OSDN Git Service

DVB configures added.
[rec10/rec10-git.git] / iRec10EPG / trunk / src / iRec10EPG.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # iRec10EPG Rec10 iEPG supporting tool
4 #Copyright 2009 Yukikaze
5 import os
6 import ConfigParser
7 import codecs
8 import webbrowser
9 import sys
10 import re
11 import urllib
12 mypath=os.path.dirname(sys.argv[0])
13 def rec10web(webpath,title,station,btime,etime):
14     browserpath="title="+title+"&btime="+btime+"&etime="+etime+"&station="+station
15     browserpath=urllib.quote_plus(browserpath,"=&")
16     browserpath=webpath+"?"+browserpath
17     print browserpath
18
19     webbrowser.open(browserpath,new=2)
20 def iepg2rec10webopts(path):
21     station=""
22     year=""
23     month=""
24     date=""
25     start=""
26     end=""
27     title=""
28
29     for line in codecs.open(path,'r','shift_jis'):
30         if  re.search('station:',line):
31             station=line.replace("station:","")
32             station=station.replace(" ","")
33             station=station.replace("\r\n","")
34         elif re.search('year:',line):
35             year=line.replace("year:","")
36             year=year.replace(" ","")
37             year=year.replace("\r\n","")
38         elif re.search('month:',line):
39             month=line.replace("month:","")
40             month=month.replace(" ","")
41             month=month.replace("\r\n","")
42         elif re.search('date:',line):
43             date=line.replace("date:","")
44             date=date.replace(" ","")
45             date=date.replace("\r\n","")
46         elif re.search('start:',line):
47             start=line.replace("start:","")
48             start=start.replace(" ","")
49             start=start.replace("\r\n","")
50         elif re.search('end:',line):
51             end=line.replace("end:","")
52             end=end.replace(" ","")
53             end=end.replace("\r\n","")
54         elif re.search('program-title:',line):
55             title=line.replace("program-title:","")
56             title=title.replace(" ","")
57             title=title.replace("\r\n","")
58     ret={}
59     ret['title']=title.encode('UTF-8')
60     ret['btime']=year+"-"+month+"-"+date+" "+start+":00"
61     ret['btime']=ret['btime'].encode('UTF-8')
62     ret['etime']=year+"-"+month+"-"+date+" "+end+":00"
63     ret['etime']=ret['etime'].encode('UTF-8')
64     ret['station']=station.encode('UTF-8')
65     return ret
66
67
68 confp=ConfigParser.SafeConfigParser()
69 Conf=os.path.join(mypath, 'setting.ini')
70 confp.read(Conf)
71 rec10path=confp.get('path','rec10web')
72 print rec10path
73 argvs=sys.argv
74 webopt=iepg2rec10webopts(argvs[1])
75 print webopt
76
77 rec10web(rec10path,webopt['title'],webopt['station'],webopt['btime'],webopt['etime'])