-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataOutput
48 lines (44 loc) · 1.7 KB
/
DataOutput
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sqlite3
class DataOutput(object):
def __init__(self):
self.cx=sqlite3.connect('MTime.db')
self.create_table('MTime')
self.datas=[]
def create_table(self,table_name):
values='''
id integer primary key,
MovieId integer,
MovieTitle varchar(40) NOT NULL,
RatingFinal REAL NOT NULL DEFAULT 0.0,
ROtherFinal REAL NOT NULL DEFAULT 0.0,
RPictureFinal REAL NOT NULL DEFAULT 0.0,
RDirectorFinal REAL NOT NULL DEFAULT 0.0,
RStoryFinal REAL NOT NULL DEFAULT 0.0,
Usercount integer NOT NULL DEFAULT 0,
AttitudeCount integer NOT NULL DEFAULT 0,
TotalBoxOffice varchar(20) NOT NULL,
TodayBoxOffice varchar(20) NOT NULL,
Rank integer NOT NULL DEFAULT 0,
ShowDays integer NOT NULL DEFAULT 0,
isRelease integer NOT NULL
'''
self.cx.execute('CREATE TABLE IF NOT EXISTS %s(%s)'%(table_name,values))
def store_data(self,data):
if data is None:
return
self.datas.append(data)
if len(self.datas)>10:
self.output_db('MTime')
def output_db(self,table_name):
for data in self.datas:
self.cx.execute('INSERT INTO %s(MovieId,movieTitle,RatingFinal,'
'ROtherFinal,RPictureFinal,RDirectorFinal,'
'RStoryFinal,Usercount,AttitudeCount,'
'TotalBoxOffice,TodayBoxOffice,Rank,ShowDays,'
'isRelease) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)'%table_name,data)
self.datas.remove(data)
self.cx.commit()
def output_end(self):
if len(self.datas)>0:
self.output_db('MTime')
self.cx.close()