3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
19 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
20 tmppath = configreader.getPathSetting("tmp")+"/"
24 recdblist.printutf8(chtxt)
25 tnow = datetime.datetime.now()
27 lastup = datetime.datetime.strptime(chdb.searchFromCHtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
29 lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
31 dt = dt.days * 24 * 60 + dt.seconds
33 ts2epg.write(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.getChCSchFromCHtxt(chtxt)['ch'])
34 xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchFromCHtxt(chtxt)['bctype'])
35 def updateForBctype(bctype):
36 bctypel = chdb.searchFromBctype(bctype)
39 ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.searchFromBctype(bctype)['ch'])
40 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)
41 shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
43 rec10d.rec10db.update_by_bctype_epg_ch(bctype)
44 except Exception, inst:
45 recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)
46 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
47 rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2")
48 def searchTime(titletxt, timet, deltatime, chtxt):
49 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
51 deltatime = int(deltatime)
52 beforetime = time.strftime("%Y%m%d%H%M%S")
53 beforetime = time - datetime.timedelta(hours=deltatime)
54 aftertime = time + datetime.timedelta(hours=deltatime)
55 beforetime = beforetime.strftime("%Y%m%d%H%M%S")
56 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
57 one = ["", "", "", "","","",""]
59 chtxtt=chtxt.replace("_0","_%")
60 d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt)
61 for chtxtt, title, start, stop ,exp,longexp,category in d:
62 #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop)
63 p = n_gram.bigram(titletxt, title)
65 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
67 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
68 bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
71 dt = 24 * 60 * 60 * dt.days + dt.seconds + 1
73 dt = 1000-1000 * dt / (7 * 24 * 60 * 60)
77 one = [chtxtt, title, btime, etime,exp,longexp,category]
80 #recdblist.printutf8(title + ":" + str(p) + u"点")
85 def searchTimeAuto(keytxt, timet, deltatime):
86 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
88 deltatime = int(deltatime)
89 beforetime = time.strftime("%Y%m%d%H%M%S")
90 aftertime = time + datetime.timedelta(hours=deltatime)
91 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
92 d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
93 for chtxtt, title, start, stop ,exp,longexp,category in d:
95 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
97 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
98 ret.append([chtxtt, title, btime, etime,exp,longexp,category])
100 def countSchedule(btime,etime):
102 return rec num (int return[0]:TE /int return[1]:BS/CS)
113 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
115 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
116 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
118 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
119 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
126 times = list(set(times))
130 for i in xrange(0, len(times)-2, 1):
133 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
134 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
135 ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1)
136 if retcount[0] < ret1[0]:
137 retcount[0] = ret1[0]
138 if retcount[1] < ret1[1]:
139 retcount[1] = ret1[1]
142 def searchSchedule(btime,etime):
144 return rec num (int return[0]:TE /int return[1]:BS/CS)
155 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
157 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
158 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
160 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
161 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
168 times = list(set(times))
172 for i in xrange(0, len(times)-2, 1):
175 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
176 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
177 ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1)
182 def countEpgSchedule(epgbtime,epgetime):
184 return rec num (int return[0]:TE /int return[1]:BS/CS)
195 dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime)
198 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
199 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
201 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
202 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
209 times = list(set(times))
213 for i in xrange(0, len(times)-1, 1):
216 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
217 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
218 ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1)
219 if retcount[0] < ret1[0]:
220 retcount[0] = ret1[0]
221 if retcount[1] < ret1[1]:
222 retcount[1] = ret1[1]
224 def searchEpgSchedule(epgbtime,epgetime):
226 return rec num (int return[0]:TE /int return[1]:BS/CS)
237 dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
239 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
240 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
242 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
243 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
250 times = list(set(times))
254 for i in xrange(0, len(times)-2, 1):
257 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
258 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
259 ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)