Mercurial > hg > MPIWGWeb
diff cleanDBUp.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cleanDBUp.py Thu Jan 10 17:52:13 2013 +0100 @@ -0,0 +1,51 @@ +"""loesche alle doppelten Personeneintraege aus personal_www""" +try: + import psycopg2 as psycopg + psyco = 2 +except: + import psycopg + psyco = 1 + + +dsn="dbname=personalwww host=xserve02a user=mysql password=e1nste1n" +dbCon = psycopg.connect(dsn) +db = dbCon.cursor() + +#find all keys + +qstr="select key from personal_www group by key" +db.execute(qstr) +res=db.fetchall() +keys=[x[0] for x in res] +print keys +for key in keys: + qstr="select id,publish_the_data from personal_www where key='%s' "%key + db.execute(qstr) + res=db.fetchall() + + deleteL={} #use hash to generate an unique list of keys + foundPublish=None + for x in res: + if x[1]=="yes": + foundPublish=x[1] + else: + deleteL[x[0]]=True + + delete=deleteL.keys() + if (len(delete)>0) and (not foundPublish): #keiner auf publish, loesche alle bis auf den letzten + del delete[-1] + + + for x in delete: + if x is not None: + qstr="delete from personal_www where id='%s'" %x + + print qstr + db.execute(qstr) + dbCon.commit() + + + + + + \ No newline at end of file