OSDN Git Service

put DB accessing functions together(dbSQLite.py).
[rec10/rec10-git.git] / rec10 / trunk / src / chdb.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5  # モジュール属性 argv を取得するため
6 import rec10d
7
8 def ontvsearch(ontvin):
9     ret=[]
10     for datum in rec10d.rec10db.select_by_ontv_chdata(ontvin):
11         rett={'bctype':datum[0],'ontv':datum[1],'chtxt':datum[2],'ch':datum[3],'csch':datum[4],'update':datum[5]}
12         ret.append(rett)
13     return ret[0]
14 def chtxtsearch(chtxtin):
15     ret=[]
16     for datum in rec10d.rec10db.select_by_chtxt_chdata(chtxtin):
17         rett={'bctype':datum[0],'ontv':datum[1],'chtxt':datum[2],'ch':datum[3],'csch':datum[4],'update':datum[5]}
18         ret.append(rett)
19     return ret[0]
20 def bctypesearch(bctypein):
21     ret=[]
22     for datum in rec10d.rec10db.select_by_bctype_chdata(bctypein):
23         rett={'bctype':datum[0],'ontv':datum[1],'chtxt':datum[2],'ch':datum[3],'csch':datum[4],'update':datum[5]}
24         ret.append(rett)
25     return ret[0]
26 def chsearch(chin):
27     ret=[]
28     for datum in rec10d.rec10db.select_by_ch_chdata(chin):
29         rett={'bctype':datum[0],'ontv':datum[1],'chtxt':datum[2],'ch':datum[3],'csch':datum[4],'update':datum[5]}
30         ret.append(rett)
31     return ret[0]
32 def getall():
33     ret=[]
34     for datum in rec10d.rec10db.select_all_chdata():
35         rett={'bctype':datum[0],'ontv':datum[1],'chtxt':datum[2],'ch':datum[3],'csch':datum[4],'update':datum[5]}
36         ret.append(rett)
37     return ret[0]
38 def update():
39     ret=[]
40     CSupdate=0
41     CS2update=0
42     BSupdate=0
43     for datum in rec10d.rec10db.select_get_update_chdata("6"):
44         bctype=datum[0]
45         chtxt=datum[1]
46         print bctype
47         if bctype=="cs" or bctype==u"cs":
48             if CSupdate==0:
49                 ret.append(u"cs")
50                 CSupdate=1
51                 print "csの番組表取得開始"
52                 rec10d.rec10db.update_by_bctype_chdata(bctype)
53         elif bctype=="cs2" or bctype==u"cs2":
54             if CS2update==0:
55                 ret.append(u"cs2")
56                 CS2update=1
57                 print "cs2の番組表取得開始"
58                 rec10d.rec10db.update_by_bctype_chdata(bctype)
59         elif bctype=="bs" or bctype==u"bs":
60             if BSupdate==0:
61                 ret.append(u"bs")
62                 BSupdate=1
63                 print "bsの番組表取得開始"
64                 rec10d.rec10db.update_by_bctype_chdata(bctype)
65         else:
66             ret.append(bctype)
67             print bctype
68             print "取得開始"
69             rec10d.rec10db.update_by_bctype_and_chtxt_chdata(bctype,chtxt)
70     print ret
71     return ret
72 #def viewall():
73 #    db=sqlite3.connect(dbpath)
74 #    for bctype, ontv, chtxt, ch, csch ,updatetime in db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata"):
75 #        print (bctype+","+ontv+","+chtxt+","+ch+","+csch+","+updatetime)
76 #    db.close()
77 #def updateall():
78
79 #print ontvsearch("1062.ontvjapan.com")