frazoj2mysql
changeset 0 6371497b4e53
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frazoj2mysql	Thu May 18 22:59:47 2006 +0200
@@ -0,0 +1,43 @@
+#!/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()