def init_bookmark(db): db.cur.execute("select * from `%s`.`%s`" % (DB_OUT, TABLE_BOOKMARK)) if db.cur.rowcount != 1: raise Exception("Invalid bookmark rowcount") row = db.cur.fetchone() bookmark = dict() bookmark["ymd"] = lbeymd.lbeymd(row["ymd"]) if not bookmark["ymd"].valid: raise Exception("Invalid bookmark table name") bookmark["id"] = row["max_id"] return bookmark
dbin.cur.execute(sqlstr) while True: row = dbin.cur.fetchone() if row is None: break pkgname = row["package_name"] uninstall_callers = set(row["uninstall_caller"].split("\n")) for uninstall_caller in uninstall_callers: update_result(dbout, pkgname, uninstall_caller) # save bookmark every 1000 records (not 1000 records with valid uninstall_caller) if bookmark["id"] + 1000 < row["id"]: bookmark["id"] = row["id"] save_bookmark(dbout, bookmark) if __name__ == "__main__": dbin = lbedb.MySQL(DB_HOST, DB_USER, DB_PASSWD) dbout = lbedb.MySQL(DB_HOST, DB_USER, DB_PASSWD) bookmark = init_bookmark(dbout) print bookmark["ymd"].toString(), bookmark["id"] print lbeymd.lbeymd().toString() while int(bookmark["ymd"].toString()) < int(lbeymd.lbeymd().toString()) - 2: # out backend data are 2 days behind the ready date parse_table(dbin, dbout, bookmark) bookmark["ymd"].inc() bookmark["id"] = 0 save_bookmark(dbout, bookmark)