def download(): has_more=True cursor=None while has_more: result=client.delta(cursor=cursor) entries=result["entries"] reset=result["reset"] cursor=result["cursor"] has_more=result["has_more"] print "found:%s"%len(entries) for item in entries: path=item[0] print path db.put(path,ujson.dumps(item)) # dat=item[1]["modified"] print item print cursor print reset print has_more
def download(): has_more = True cursor = None while has_more: result = client.delta(cursor=cursor) entries = result["entries"] reset = result["reset"] cursor = result["cursor"] has_more = result["has_more"] print "found:%s" % len(entries) for item in entries: path = item[0] print path db.put(path, ujson.dumps(item)) # dat=item[1]["modified"] print item print cursor print reset print has_more
print "wrote new token" else: sess.set_token(token_key, token_secret) client = client.DropboxClient(sess) print "client constructed" CURSOR_KEY = "cursor.txt" while True: time.sleep(5) print "check" cursor = None if (os.path.isfile(CURSOR_KEY)): f = open(CURSOR_KEY, 'r') cursor = f.read() f.close() ret = client.delta(cursor) cursor = ret['cursor'] f = open(CURSOR_KEY, 'w') f.write(cursor) f.close() entries = ret['entries'] for e in entries: meta = e[1] if not meta is None: print meta['path'] + " modified"
log.info( 'read pull state from file' ) try: with open( cursor_filename, 'rb' ) as f: cursor = pickle.load( f ) except IOError as e: cursor = None pass log.info( 'fetch available deltas' ) # ( cf. https://www.dropbox.com/developers/reference/api#delta ) more = True notify = False folder_to_watch = folder_to_watch.decode( 'utf-8', 'replace' ) while more: delta = client.delta( cursor=cursor ) cursor = delta[ 'cursor' ] more = delta[ 'has_more' ] # check if delta includes any entries from desired folder for entry in delta[ 'entries' ]: if re.match( folder_to_watch, entry[0] ): notify = True break log.info( 'write pull state to file' ) try: with open( cursor_filename, 'wb' ) as f: pickle.dump( cursor, f, pickle.HIGHEST_PROTOCOL ) except IOError as ioerr: print "Check your path configurations in config.py - the specified cursor path doesn't seem to exist."