Created
November 2, 2017 21:04
-
-
Save aeris/25ea4d73e6dd94b6b6b86c328941458e to your computer and use it in GitHub Desktop.
Export photo Cozy v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'typhoeus' | |
require 'oj' | |
require 'base64' | |
require 'fileutils' | |
def get(url, params = {}) | |
res = Typhoeus.get url, params: params, headers: {'Accept' => 'application/json'} | |
Oj.load(res.body) | |
end | |
def content(database, id, rev) | |
url = [database, id].join '/' | |
get url, rev: rev, attachments: true | |
end | |
database = 'http://localhost:5984/cozy' | |
get(database + '/_design/photo/_view/all')['rows'].collect { |r| r['value'] }.each do |doc| | |
title = File.join 'export', doc['title'] | |
raw = doc['binary']['raw'] | |
raw = content database, raw['id'], raw['rev'] | |
raw = raw['_attachments']['raw']['data'] | |
raw = Base64.decode64 raw | |
FileUtils.mkdir_p File.dirname title | |
File.open(title, 'wb') { |f| f.write raw } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment