3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
15 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
16 tmppath = configreader.getpath("tmp")+"/"
21 tnow = datetime.datetime.now()
23 lastup = datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
25 lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
27 dt = dt.days * 24 * 60 + dt.seconds
29 ts2epg.write(tmppath + chtxt + "epgdata.xml", chdb.chtxtsearch(chtxt)['ch'])
30 xml2db.xml2db(tmppath + chtxt + "epgdata.xml", chdb.chtxtsearch(chtxt)['bctype'])
32 bctypel = chdb.bctypesearch(bctype)
35 ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(bctype)['ch'])
36 xml2db.xml2db(tmppath + bctype + "epgdata.xml", bctype)
37 shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
38 rec10d.rec10db.update_by_bctype_chdata(bctype)
39 except Exception, inst:
42 xml2db.xml2db(tmppath + bctype + "epgdata.bak.xml", bctype)
43 rec10d.rec10db.update_status_by_bctype_chdata(bctype, "2")
44 def updatebc_bak(bctype):
46 update epg data by .bak file
48 xml2db.xml2db(tmppath + bctype + "epgdata.bak.xml", bctype)
49 def searchtime2(titletxt, timet, deltatime, chtxt):
50 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
52 deltatime = int(deltatime)
53 beforetime = time.strftime("%Y%m%d%H%M%S")
54 aftertime = time + datetime.timedelta(hours=deltatime)
55 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
56 one = ["", "", "", ""]
58 d = rec10d.rec10db.select_by_time_ngram_tv(beforetime, aftertime, chtxt)
59 for chtxtt, title, start, stop ,exp,longexp,category in d:
60 #print chtxtt+":"+title+":"+start+":"+stop
61 p = n_gram.bigram(titletxt, title)
63 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
65 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
66 bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
68 dt = 24 * 60 * 60 * dt.days + dt.seconds + 1
70 dt = 1000-1000 * dt / (7 * 24 * 60 * 60)
75 one = [chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')]
78 print title + ":" + str(p) + "点"
82 def searchtime_auto(keytxt, timet, deltatime):
83 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
85 deltatime = int(deltatime)
86 beforetime = time.strftime("%Y%m%d%H%M%S")
87 aftertime = time + datetime.timedelta(hours=deltatime)
88 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
89 d = rec10d.rec10db.select_by_time_auto_suggest_tv(keytxt,beforetime, aftertime)
90 for chtxtt, title, start, stop ,exp,longexp,category in d:
92 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
94 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
95 ret.append([chtxtt, title.encode('utf-8'), btime, etime,exp.encode('UTF-8'),longexp.encode('UTF-8'),category.encode('UTF-8')])