txt2db.py
author viric <viriketo@gmail.com>
Mon, 03 Sep 2012 23:35:31 +0200
branchgo
changeset 7 d5750f4e6e8c
parent 0 6371497b4e53
permissions -rwxr-xr-x
Adding a first attempt at go code

#!/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()