0
|
1 |
#!/usr/bin/python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
import shelve,string,os
|
|
5 |
|
|
6 |
|
|
7 |
sourcefile = 'vortoj-ru-ca.txt'
|
|
8 |
dbfile = 'vortoj-ru-ca.sdb'
|
|
9 |
try:
|
|
10 |
os.remove(dbfile)
|
|
11 |
except:
|
|
12 |
print "File '%s' doesn't exist. Creating..." % dbfile
|
|
13 |
else:
|
|
14 |
print "File '%s' exist. Wipping..." % dbfile
|
|
15 |
|
|
16 |
dbase = shelve.open(dbfile)
|
|
17 |
|
|
18 |
# Read txt
|
|
19 |
file = open(sourcefile, 'r')
|
|
20 |
|
|
21 |
for line in file:
|
|
22 |
line = line.rstrip('\n')
|
|
23 |
words = string.split(line, '\t')
|
|
24 |
print "Adding:", words[0], '=>', words[2]
|
|
25 |
dbase[words[0]] = words[2]
|
|
26 |
|
|
27 |
file.close()
|
|
28 |
|
|
29 |
dbase.close()
|