3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
18 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
19 tmppath = configreader.getpath("tmp")+"/"
23 recdblist.printutf8(chtxt)
24 tnow = datetime.datetime.now()
26 lastup = datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
28 lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
30 dt = dt.days * 24 * 60 + dt.seconds
32 ts2epg.write(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.chtxtsearch(chtxt)['ch'])
33 xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.chtxtsearch(chtxt)['bctype'])
35 bctypel = chdb.bctypesearch(bctype)
38 ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(bctype)['ch'])
39 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)
40 shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
42 rec10d.rec10db.update_by_bctype_epg_ch(bctype)
43 except Exception, inst:
44 print "error occurs in updatebc(epgdb)"
47 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
48 rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2")
49 def updatebc_bak(bctype):
51 update epg data by .bak file
53 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
54 def searchtime2(titletxt, timet, deltatime, chtxt):
55 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
57 deltatime = int(deltatime)
58 beforetime = time.strftime("%Y%m%d%H%M%S")
59 beforetime = time - datetime.timedelta(hours=deltatime)
60 aftertime = time + datetime.timedelta(hours=deltatime)
61 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
62 one = ["", "", "", "","","",""]
64 d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxt)
65 for chtxtt, title, start, stop ,exp,longexp,category in d:
66 #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop)
67 p = n_gram.bigram(titletxt, title)
69 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
71 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
72 bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
75 dt = 24 * 60 * 60 * dt.days + dt.seconds + 1
77 dt = 1000-1000 * dt / (7 * 24 * 60 * 60)
81 one = [chtxtt, title, btime, etime,exp,longexp,category]
84 recdblist.printutf8(title + ":" + str(p) + u"点")
88 def searchtime_auto(keytxt, timet, deltatime):
89 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
91 deltatime = int(deltatime)
92 beforetime = time.strftime("%Y%m%d%H%M%S")
93 aftertime = time + datetime.timedelta(hours=deltatime)
94 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
95 d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
96 for chtxtt, title, start, stop ,exp,longexp,category in d:
98 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
100 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
101 ret.append([chtxtt, title, btime, etime,exp,longexp,category])
103 def count_schedule(btime,etime):
105 return rec num (int return[0]:TE /int return[1]:BS/CS)
116 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
118 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
119 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
121 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
122 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
129 times = list(set(times))
133 for i in xrange(0, len(times)-2, 1):
136 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
137 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
138 ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1)
139 if retcount[0] < ret1[0]:
140 retcount[0] = ret1[0]
141 if retcount[1] < ret1[1]:
142 retcount[1] = ret1[1]
145 def search_schedule(btime,etime):
147 return rec num (int return[0]:TE /int return[1]:BS/CS)
158 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
160 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
161 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
163 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
164 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
171 times = list(set(times))
175 for i in xrange(0, len(times)-2, 1):
178 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
179 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
180 ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1)
185 def count_epgschedule(epgbtime,epgetime):
187 return rec num (int return[0]:TE /int return[1]:BS/CS)
198 dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
201 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
202 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
204 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
205 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
212 times = list(set(times))
216 for i in xrange(0, len(times)-1, 1):
219 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
220 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
221 ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1)
222 if retcount[0] < ret1[0]:
223 retcount[0] = ret1[0]
224 if retcount[1] < ret1[1]:
225 retcount[1] = ret1[1]
230 def search_epgschedule(epgbtime,epgetime):
232 return rec num (int return[0]:TE /int return[1]:BS/CS)
243 dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
245 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
246 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
248 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
249 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
256 times = list(set(times))
260 for i in xrange(0, len(times)-2, 1):
263 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
264 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
265 ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)