@@ -0,0 +1,2514 @@
+import sys, os, dropbox, time%0Afrom datetime import datetime%0A%0AAPP_KEY = 'hacwza866qep9o6'%0AAPP_SECRET = 'kgipko61g58n6uc'%0ADELAY = 0.2 # delay between each file (try to stay under API rate limits)%0A%0A%0Adef authorize():%0A    flow = dropbox.client.DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET)%0A    authorize_url = flow.start()%0A    print '1. Go to: ' + authorize_url%0A    print '2. Click %22Allow%22 (you might have to log in first)'%0A    print '3. Copy the authorization code.'%0A    code = raw_input(%22Enter the authorization code here: %22).strip()%0A    access_token, user_id = flow.finish(code)%0A    return access_token%0A%0A%0Adef login(token_save_path):%0A    if os.path.exists(token_save_path):%0A        with open(token_save_path) as token_file:%0A            access_token = token_file.read()%0A    else:%0A        access_token = authorize()%0A        with open(token_save_path, 'w') as token_file:%0A            token_file.write(access_token)%0A    return dropbox.client.DropboxClient(access_token)%0A%0A%0Adef parse_date(s):%0A    a = s.split('+')%5B0%5D.strip()%0A    return datetime.strptime(a, '%25a, %25d %25b %25Y %25H:%25M:%25S')%0A%0A%0Adef restore_file(client, path, cutoff_datetime, verbose=False):%0A    revisions = client.revisions(path)%0A    revision_dict = %7B%7D%0A    for revision in revisions:%0A        mod_datetime = parse_date(revision%5B'modified'%5D)%0A        if mod_datetime %3C cutoff_datetime:%0A            revision_dict%5Bmod_datetime%5D = revision%0A%0A    if len(revision_dict) %3E 0:%0A        target_datetime = max(revision_dict.keys())%0A        rev = revision_dict%5Btarget_datetime%5D%5B'rev'%5D%0A        if verbose:%0A            print path, target_datetime%0A        client.restore(path, rev)%0A    else:%0A        if verbose:%0A            print path, 'DID NOT EXIST BEFORE CUTOFF'%0A%0A%0Adef restore_folder(client, path, cutoff_datetime, verbose=False):%0A    if verbose:%0A        print 'Restoring folder: ' + path%0A    folder = client.metadata(path, list=True, include_deleted=True)%0A    for item in folder.get('contents', %5B%5D):%0A        if item.get('is_dir', False):%0A            restore_folder(client, item%5B'path'%5D, cutoff_datetime, verbose)%0A        else:%0A            restore_file(client, item%5B'path'%5D, cutoff_datetime, verbose)%0A        time.sleep(DELAY)%0A%0A%0Adef main():%0A    if len(sys.argv) != 3:%0A        sys.exit('usage: %7B0%7D ROOTPATH YYYY-MM-DD'.format(sys.argv%5B0%5D))%0A    root_path, cutoff = sys.argv%5B1:%5D%0A    cutoff_datetime = datetime(*map(int, cutoff.split('-')))%0A    client = login('token.dat')%0A    restore_folder(client, root_path, cutoff_datetime, verbose=True)%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add restore.py