Mercurial > hg > MPIWGWeb
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:bca61e893fcc |
|---|---|
| 1 """loesche alle doppelten Personeneintraege aus personal_www""" | |
| 2 try: | |
| 3 import psycopg2 as psycopg | |
| 4 psyco = 2 | |
| 5 except: | |
| 6 import psycopg | |
| 7 psyco = 1 | |
| 8 | |
| 9 | |
| 10 dsn="dbname=personalwww host=xserve02a user=mysql password=e1nste1n" | |
| 11 dbCon = psycopg.connect(dsn) | |
| 12 db = dbCon.cursor() | |
| 13 | |
| 14 #find all keys | |
| 15 | |
| 16 qstr="select key from personal_www group by key" | |
| 17 db.execute(qstr) | |
| 18 res=db.fetchall() | |
| 19 keys=[x[0] for x in res] | |
| 20 print keys | |
| 21 for key in keys: | |
| 22 qstr="select id,publish_the_data from personal_www where key='%s' "%key | |
| 23 db.execute(qstr) | |
| 24 res=db.fetchall() | |
| 25 | |
| 26 deleteL={} #use hash to generate an unique list of keys | |
| 27 foundPublish=None | |
| 28 for x in res: | |
| 29 if x[1]=="yes": | |
| 30 foundPublish=x[1] | |
| 31 else: | |
| 32 deleteL[x[0]]=True | |
| 33 | |
| 34 delete=deleteL.keys() | |
| 35 if (len(delete)>0) and (not foundPublish): #keiner auf publish, loesche alle bis auf den letzten | |
| 36 del delete[-1] | |
| 37 | |
| 38 | |
| 39 for x in delete: | |
| 40 if x is not None: | |
| 41 qstr="delete from personal_www where id='%s'" %x | |
| 42 | |
| 43 print qstr | |
| 44 db.execute(qstr) | |
| 45 dbCon.commit() | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 |
