"""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()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>