print "No connection to DB"
exit()
+def ListDups(limit=100):
+ if database:
+ c = database.cursor()
+ c.execute('SELECT b.title,l.author,max(b.id) id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book group by b.title,l.author having count(*)>%s',(limit))
+ return c.fetchall()
+ else:
+ print "No connection to DB"
+ exit()
+
+def ListByTitleAndAuthor(title,author,id=0):
+ if database:
+ c = database.cursor()
+ c.execute('SELECT b.id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book and b.title=%s and l.author=%s and b.id<>%s',(title,author,id))
+ return c.fetchall()
+ else:
+ print "No connection to DB"
+ exit()
+
+
def Commit():
if database:
database.commit()
db.DelBook(id)
db.Commit()
+def RemoveDups(limit = 100):
+ if limit<2:
+ return
+ id_to_del=set([])
+ recs = db.ListDups(limit);
+ for rec in recs:
+ ids = db.ListByTitleAndAuthor(rec[0],rec[1],rec[2])
+ for id in ids:
+ id_to_del.add(id)
+ for id in id_to_del:
+ print "\r Deleting %s..." % (id)
+ DelBook(id)
+
def main():
+ print "Processing...\r"
ProcessDir(db.tmp_files)
CompressAll(2000)