-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathup-database.py
More file actions
60 lines (54 loc) · 1.26 KB
/
up-database.py
File metadata and controls
60 lines (54 loc) · 1.26 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
import sqlite3
order=['name','place','time','white','black','rule','tiehuan','result','fromb']
orderb=['id','name','place','time','result','tiehuan','white','black','fromb','fb','rule']
dict={
'place':'PC',
'time':'DT',
'name':'EV',
'white':'PW',
'black':'PB',
'rule':'RU',
'tiehuan':'KM',
'fromb':'SO',
'result':'RE'
}
def crez(cre):
e=cre.cursor()
e.execute('''CREATE TABLE weiqi(id char(18) PRIMARY KEY,date text);''')
cre.commit()
def hb(w):
stra="(;AP[iwdb.cn]"
for info in order:
if w[info]=='':
continue
stra=stra+dict[info]+"["+w[info]+"]"
w['fb']=w['fb']+" "
stra=stra+w['fb'][1:-1]
return stra
def dih(item):
a={}
i=0
for info in orderb:
a[info]=item[i]
if a[info]==None:
a[info]=''
i=i+1
return a
cre=sqlite3.connect("up-data.db")
#crez(cre)
e=cre.cursor()
cre_old=sqlite3.connect("weiqi.db")
ol=cre_old.cursor()
a=ol.execute("select id,name,place,time,result,tiehuan,white,black,fromb,fb,rule from weiqi;")
i=0
for item in a:
a=[item[0]]
a.append(hb(dih(item)))
e.execute('''INSERT INTO weiqi(id,date)values(?,?)''',a)
i=i+1
if i%100==1:
print(i)
cre.commit()
cre_old.close()
cre.close()
#print(hb(t))