File:  [Repository] / MPIWGWeb / Attic / wikisqldumpToSQL.py
Revision 1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Wed Sep 13 08:17:33 2006 UTC (17 years, 9 months ago) by dwinter
Branches: r2
tools and methods for index generation

    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()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>