0
|
1 |
#!/usr/bin/python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
import sys,string,os,MySQLdb,re
|
|
5 |
|
|
6 |
database = 'lingvigilo'
|
|
7 |
dbuser = 'lingvigilouser'
|
|
8 |
dbpass = 'carrinclo'
|
|
9 |
dbtable = 'frazoj_ru_ca'
|
|
10 |
|
|
11 |
db = MySQLdb.connect(host='vicerveza',user=dbuser,passwd=dbpass,db=database)
|
|
12 |
|
|
13 |
cursor = db.cursor()
|
|
14 |
|
|
15 |
if (len(sys.argv) != 2):
|
|
16 |
print "Diru nomon de dosiero."
|
|
17 |
sys.exit()
|
|
18 |
else:
|
|
19 |
sourcefile=sys.argv[1]
|
|
20 |
|
|
21 |
|
|
22 |
# Read txt
|
|
23 |
file = open(sourcefile, 'r')
|
|
24 |
|
|
25 |
for line in file:
|
|
26 |
# Traiem l'INTRO final
|
|
27 |
line = line.rstrip('\n')
|
|
28 |
|
|
29 |
# Arreglem cometes simples per a sql
|
|
30 |
line = re.sub(r"'",r"\'", line)
|
|
31 |
|
|
32 |
# Separem per \t
|
|
33 |
words = string.split(line, '\t')
|
|
34 |
|
|
35 |
print "Aldonante:", words[0], '=>', words[1]
|
|
36 |
|
|
37 |
cursor.execute('INSERT INTO ' + dbtable +
|
|
38 |
' (vorto,frazo) '+
|
|
39 |
'VALUES(\'%s\',\'%s\');' % (words[0], words[1]))
|
|
40 |
|
|
41 |
db.close()
|
|
42 |
|
|
43 |
file.close()
|