Skip to content

Instantly share code, notes, and snippets.

@mxswd
Last active October 13, 2015 14:18
Show Gist options
  • Select an option

  • Save mxswd/4209006 to your computer and use it in GitHub Desktop.

Select an option

Save mxswd/4209006 to your computer and use it in GitHub Desktop.
require 'faraday'
require 'json'
require 'couchrest'
@couch = CouchRest.new("http://127.0.0.1:5984")
@db = @couch.create_db('items')
# http://127.0.0.1:5984/_utils/
# TODO: download images as attachments
TOKEN = ""
def fburl(r, token)
"https://graph.facebook.com/#{r}?access_token=#{token}"
end
def get_data(url)
response = Faraday.get url
data = JSON.parse(response.body)
if data["error"]
puts "Error in auth"
exit(1)
end
data
end
downloading = true
data = get_data(fburl(???, TOKEN))
while downloading
data["data"].each do |post|
post["_id"] = post["id"]
@db.save_doc(post)
end
data = get_data(data["paging"]["next"])
downloading = !!data["paging"]
end
require 'faraday'
require 'json'
conn = Faraday.new("http://localhost:5984")
resp = conn.post do |req|
req.url '/test/_bulk_docs'
req.headers['Content-Type'] = 'application/json'
req.body = JSON::dump({docs: obj})
end
puts resp.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment