Mercurial > hg > MPIWGWeb
comparison wikisqldumpToSQL.py @ 0:bca61e893fcc
first checkin of MPIWGWeb r2 branch from CVS into mercurial
author | casties |
---|---|
date | Thu, 10 Jan 2013 17:52:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bca61e893fcc |
---|---|
1 import psycopg | |
2 | |
3 o = psycopg.connect('dbname=authorities user=dwinter password=3333',serialize=0) | |
4 c = o.cursor() | |
5 | |
6 import re | |
7 | |
8 def quote(str): | |
9 str=str.replace("'","\\\'") | |
10 str=str.replace("@","\\\'") | |
11 return str#.encode('utf-8') | |
12 | |
13 filename="/Users/dwinter/Desktop/dewiki-20060908-categorylinks.sql" | |
14 txt=file(filename).read() | |
15 datas=re.findall("(VALUES.*)",txt) | |
16 for data in datas: | |
17 print data | |
18 txt=data.replace("VALUES","") | |
19 data=re.findall("\((.*?)\)",txt) | |
20 print len(data) | |
21 for result in data: | |
22 result=result.replace("\\\'","@") | |
23 | |
24 new=re.findall("\'(.*?)\'",result) | |
25 if len(new)>1: | |
26 if (len(new)>0) and ((new[0]=='Mann') or (new[0]=="Frau")): | |
27 try: | |
28 firstname=new[1].split(",")[1].lstrip() | |
29 except: | |
30 firstname="" | |
31 lastname=new[1].split(",")[0].lstrip() | |
32 | |
33 print "INSERT into persons (firstname,lastname) VALUES ('%s','%s')"% (quote(firstname),quote(lastname)) | |
34 c.execute("INSERT into persons (firstname,lastname) VALUES ('%s','%s')"% (quote(firstname),quote(lastname))) | |
35 c.commit() |