3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
19 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
20 tmppath = configreader.getpath("tmp")+"/"
24 recdblist.printutf8(chtxt)
25 tnow = datetime.datetime.now()
27 lastup = datetime.datetime.strptime(chdb.chtxtsearch(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.chtxtsearch(chtxt)['ch'])
34 xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.chtxtsearch(chtxt)['bctype'])
36 bctypel = chdb.bctypesearch(bctype)
39 ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(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.Commonlogex("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 updatebc_bak(bctype):
50 update epg data by .bak file
52 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
53 def searchtime2(titletxt, timet, deltatime, chtxt):
54 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
56 deltatime = int(deltatime)
57 beforetime = time.strftime("%Y%m%d%H%M%S")
58 beforetime = time - datetime.timedelta(hours=deltatime)
59 aftertime = time + datetime.timedelta(hours=deltatime)
60 beforetime = beforetime.strftime("%Y%m%d%H%M%S")
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"点")
89 def searchtime_auto(keytxt, timet, deltatime):
90 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
92 deltatime = int(deltatime)
93 beforetime = time.strftime("%Y%m%d%H%M%S")
94 aftertime = time + datetime.timedelta(hours=deltatime)
95 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
96 d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
97 for chtxtt, title, start, stop ,exp,longexp,category in d:
99 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
101 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
102 ret.append([chtxtt, title, btime, etime,exp,longexp,category])
104 def count_schedule(btime,etime):
106 return rec num (int return[0]:TE /int return[1]:BS/CS)
117 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
119 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
120 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
122 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
123 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
130 times = list(set(times))
134 for i in xrange(0, len(times)-2, 1):
137 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
138 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
139 ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1)
140 if retcount[0] < ret1[0]:
141 retcount[0] = ret1[0]
142 if retcount[1] < ret1[1]:
143 retcount[1] = ret1[1]
146 def search_schedule(btime,etime):
148 return rec num (int return[0]:TE /int return[1]:BS/CS)
159 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
161 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
162 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
164 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
165 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
172 times = list(set(times))
176 for i in xrange(0, len(times)-2, 1):
179 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
180 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
181 ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1)
186 def count_epgschedule(epgbtime,epgetime):
188 return rec num (int return[0]:TE /int return[1]:BS/CS)
199 dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime)
202 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
203 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
205 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
206 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
213 times = list(set(times))
217 for i in xrange(0, len(times)-1, 1):
220 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
221 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
222 ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1)
223 if retcount[0] < ret1[0]:
224 retcount[0] = ret1[0]
225 if retcount[1] < ret1[1]:
226 retcount[1] = ret1[1]
228 def search_epgschedule(epgbtime,epgetime):
230 return rec num (int return[0]:TE /int return[1]:BS/CS)
241 dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
243 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
244 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
246 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
247 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
254 times = list(set(times))
258 for i in xrange(0, len(times)-2, 1):
261 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
262 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
263 ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)