def updateYQWwords(path=pathyq): filename = open(path) chinese = "" conn = connectsqlite() cnt = 1 while 1: lines = filename.readlines(1000) if not lines: break for line in lines: if line == "\n" or line == "": continue if is_cn_line(line) and not line[0].isdigit() and not "[" in line: chinese = dealstring(line) #print chinese insertAttribute(conn,chinese,cnt) cnt = cnt + 1 if line[0].isdigit(): words = line.split() #print chinese + ":" + words[1] value = [] value.append(words[1]) value.append(2) value.append(cnt-1) insertAttriToSqlite(conn,value) conn.commit() conn.close() filename.close() print cnt
def writeYQtodisk(): filename = open(pathadv) outfile = open('D:\\advout.txt','w') conn = connect() YQ = {} #results = getYQrecords(conn) results = getAdvrecords(conn) #print 'haha' for result in results: w = Word(result[1],result[3],result[4]) print result[1] YQ[result[1]] = w conn.close() print 'lala' cnt = 1 while 1: lines = filename.readlines(1000) if not lines: break for line in lines: #Blank line if line == "\n": outfile.writelines(line) #Chinese if is_cn_line(line): #print "%d : %s" %(cnt,line) cnt = 1 outfile.writelines(line) #print chinese #English Word if is_cn_line(line)==False and line != "\n": line = line.strip(' ') #line = fetch(line.lower()) line = line.lower() line = dealstring(line) tmp = YQ[line] string = "%s%s%s\n" %(str(cnt).ljust(5),tmp.word.ljust(20),tmp.meanings) outfile.writelines(string) outfile.writelines(" [" + tmp.soundmark + ']\n') cnt = cnt + 1 file.close() outfile.close()