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