def OLD_sync(localdb, user, password, since=None): db = Notes(localdb) api = Simplenote(user, password) log("LOCAL TO REMOTE:") synced_count = 0 for note in db.values(): if note["CHANGED"]: if not note.has_key("key") or note["key"].startswith(KEY_PREFIX): log("NEW NOTE") else: log("CHANGED: %s" % note["key"]) if note["key"].startswith(KEY_PREFIX): k = note["key"] del note["key"] else: k = None note = api.update(note) note["CHANGED"] = False db.update(note) if k is not None: db.remove(k) synced_count += 1 if since: rindex = api.index(since=since) log(">>>> SINCE: %s" % since) else: rindex = api.index() log("REMOTE TO LOCAL:") log(">>>> RINDEX LEN: %s" % len(rindex)) for ritem in rindex: key = ritem["key"] if key not in db.keys(deleted=True): log(" NEW: %s" % (key)) db.update(api.get(key)) synced_count += 1 litem = db.get(key) if ritem["syncnum"] > litem["syncnum"]: log(" UPD: %s" % (key)) db.update(api.get(key)) synced_count += 1 log("CLEAN UP:") if since is None: rkeys = api.keys().keys() for k in db.keys(deleted=True): if k not in rkeys: log(" DEL: %s" % k) db.remove(k) synced_count += 1 else: for k in db.keys(deleted=True): litem = db.get(k) if litem["deleted"] != 0: log(" DEL: %s" % k) db.remove(k) sys.stderr.write("Synced %s notes.\n" % synced_count) return time.time()
def sync(dbpath, user, password): notes = Notes(dbpath) log("LOCAL TO REMOTE:") synced_count = 0 for note in notes.values(): if note["CHANGED"]: note["content"] = notes.getContent(note["key"]) if note["key"].startswith(KEY_PREFIX): log("NEW NOTE") k = note["key"] del note["key"] else: log("CHANGED: %s" % note["key"]) k = None note = api.update(note) note["CHANGED"] = False db.update(note) if k is not None: db.remove(k) synced_count += 1