frazoj2mysql
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 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()