txt2db.py
author viric@llimona
Thu, 18 May 2006 23:06:22 +0200
changeset 1 d89c6e7de299
parent 0 6371497b4e53
permissions -rwxr-xr-x
File found in working directory. Probably not finished.

#!/usr/bin/python
# -*- coding: utf-8 -*-

import shelve,string,os


sourcefile = 'vortoj-ru-ca.txt'
dbfile = 'vortoj-ru-ca.sdb'
try:
	os.remove(dbfile)
except:
	print "File '%s' doesn't exist. Creating..." % dbfile
else:
	print "File '%s' exist. Wipping..." % dbfile

dbase = shelve.open(dbfile)

# Read txt
file = open(sourcefile, 'r')

for line in file:
	line = line.rstrip('\n')
	words = string.split(line, '\t')
	print "Adding:", words[0], '=>', words[2]
	dbase[words[0]] = words[2]

file.close()
	
dbase.close()