Events don't work as I expect. tab makes save sentence, while enter should be
doing that.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,string,os,MySQLdb,re
database = 'lingvigilo'
dbuser = 'lingvigilouser'
dbpass = 'carrinclo'
dbtable = 'frazoj_ru_ca'
db = MySQLdb.connect(host='vicerveza',user=dbuser,passwd=dbpass,db=database)
cursor = db.cursor()
if (len(sys.argv) != 2):
print "Diru nomon de dosiero."
sys.exit()
else:
sourcefile=sys.argv[1]
# Read txt
file = open(sourcefile, 'r')
for line in file:
# Traiem l'INTRO final
line = line.rstrip('\n')
# Arreglem cometes simples per a sql
line = re.sub(r"'",r"\'", line)
# Separem per \t
words = string.split(line, '\t')
print "Aldonante:", words[0], '=>', words[1]
cursor.execute('INSERT INTO ' + dbtable +
' (vorto,frazo) '+
'VALUES(\'%s\',\'%s\');' % (words[0], words[1]))
db.close()
file.close()