3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
14 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
18 tnow = datetime.datetime.now()
20 lastup = datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
22 lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
24 dt = dt.days * 24 * 60 + dt.seconds
26 ts2epg.write(tmppath + chtxt + "epgdate.xml", chdb.chtxtsearch(chtxt)['ch'])
27 xml2db.xml2db(tmppath + chtxt + "epgdate.xml", chdb.chtxtsearch(chtxt)['bctype'])
29 bctypel = chdb.bctypesearch(bctype)
32 ts2epg.write(tmppath + bctype + "epgdate.xml", chdb.bctypesearch(bctype)['ch'])
33 xml2db.xml2db(tmppath + bctype + "epgdate.xml", bctype)
34 shutil.copyfile(tmppath + bctype + "epgdate.xml", tmppath + bctype + "epgdate.bak.xml")
35 rec10d.rec10db.update_by_bctype_chdata(bctype)
36 except Exception, inst:
39 xml2db.xml2db(tmppath + bctype + "epgdate.bak.xml", bctype)
40 rec10d.rec10db.update_status_by_bctype_chdata(bctype, "2")
41 def updatebc_bak(bctype):
43 update epg data by .bak file
45 xml2db.xml2db(tmppath + bctype + "epgdate.bak.xml", bctype)
46 def searchtime2(titletxt, timet, deltatime, chtxt):
47 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
49 deltatime = int(deltatime)
50 beforetime = time.strftime("%Y%m%d%H%M%S")
51 aftertime = time + datetime.timedelta(hours=deltatime)
52 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
53 one = ["", "", "", ""]
55 d = rec10d.rec10db.select_by_time_ngram_tv(beforetime, aftertime, chtxt)
56 for chtxtt, title, start, stop ,exp,longexp,category in d:
57 #print chtxtt+":"+title+":"+start+":"+stop
58 p = n_gram.bigram(titletxt, title)
60 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
62 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
63 bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
65 dt = 24 * 60 * 60 * dt.days + dt.seconds + 1
67 dt = 1000-1000 * dt / (7 * 24 * 60 * 60)
72 one = [chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')]
75 print title + ":" + str(p) + "点"
79 def searchtime_auto(keytxt, timet, deltatime):
80 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
82 deltatime = int(deltatime)
83 beforetime = time.strftime("%Y%m%d%H%M%S")
84 aftertime = time + datetime.timedelta(hours=deltatime)
85 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
86 d = rec10d.rec10db.select_by_time_auto_suggest_tv(keytxt,beforetime, aftertime)
87 for chtxtt, title, start, stop ,exp,longexp,category in d:
89 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
91 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
92 ret.append([chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')])