vortoj2mysql
author viric@llimona
Thu, 18 May 2006 23:06:22 +0200
changeset 1 d89c6e7de299
parent 0 6371497b4e53
permissions -rwxr-xr-x
File found in working directory. Probably not finished.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     1
#!/usr/bin/python
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     3
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     4
import shelve,string,os,MySQLdb,re
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     5
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     6
database = 'lingvigilo'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     7
dbuser = 'lingvigilouser'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     8
dbpass = 'carrinclo'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
     9
dbtable = 'vortoj_ru_ca'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    10
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    11
db = MySQLdb.connect(host='vicerveza',user=dbuser,passwd=dbpass,db=database)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    12
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    13
cursor = db.cursor()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    14
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    15
sourcefile = 'vortoj-ru-ca.txt'
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    16
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    17
# Connexió base de dades
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    18
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    19
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    20
# Read txt
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    21
file = open(sourcefile, 'r')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    22
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    23
cursor.execute('DELETE FROM ' + dbtable);
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    24
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    25
for line in file:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    26
	# Traiem l'INTRO final
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    27
	line = line.rstrip('\n')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    28
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    29
	# Arreglem cometes simples per a sql
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    30
	line = re.sub(r"'",r"\'", line)
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    31
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    32
	# Separem per \t
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    33
	words = string.split(line, '\t')
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    34
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    35
	print "Aldonante:", words[0], '=>', words[2]
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    36
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    37
	if words[1] == "verb":
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    38
		#print ('INSERT INTO ' + dbtable +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    39
		#	' (vorto,tipo,traduko,param1,param2) '+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    40
		#	'VALUES(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');' %
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    41
		#	(words[0], words[1], words[2], words[3], words[4]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    42
		if (len(words) == 5):
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    43
			cursor.execute('INSERT INTO ' + dbtable +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    44
				' (vorto,tipo,traduko,param1,param2) '+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    45
				'VALUES(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');' %
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    46
				(words[0], words[1], words[2], words[3],
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    47
				words[4]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    48
		else:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    49
			cursor.execute('INSERT INTO ' + dbtable +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    50
				' (vorto,tipo,traduko,param1) '+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    51
				'VALUES(\'%s\',\'%s\',\'%s\',\'%s\');' %
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    52
				(words[0], words[1], words[2], words[3]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    53
	else:
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    54
		#print ('INSERT INTO ' + dbtable +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    55
		#	' (vorto,tipo,traduko) '+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    56
		#	'VALUES(\'%s\',\'%s\',\'%s\');' % (words[0], words[1],
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    57
		#	words[2]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    58
		cursor.execute('INSERT INTO ' + dbtable +
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    59
			' (vorto,tipo,traduko) '+
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    60
			'VALUES(\'%s\',\'%s\',\'%s\');' % (words[0], words[1],
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    61
			words[2]))
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    62
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    63
db.close()
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    64
6371497b4e53 Init from svn. The wxpython is the final one.
viric@llimona
parents:
diff changeset
    65
file.close()