Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Created February 3, 2012 00:09
Show Gist options
  • Save technoweenie/1726644 to your computer and use it in GitHub Desktop.
Save technoweenie/1726644 to your computer and use it in GitHub Desktop.
export cotweet sent timeline
require 'json'
require 'fileutils'
require 'faraday'
email, pass, dir = ARGV
if !(email && pass)
puts "Pass your CoTweet email/password:"
puts
puts " $ ruby #{$0} email@example.com sekretpassword [/path/to/dump]"
puts
exit
end
def dump_cotweet(http, dir, max = nil)
http.params[:max] = max if max
res = http.get
max = nil
if res.status == 200
data = JSON.parse res.body
data['items'].each do |item|
max = item['id']
File.open File.join(dir, "#{max}.json"), 'w' do |io|
io << item.to_json
end
puts "Wrote #{max}.json"
end
dump_cotweet(http, dir, max) if max
else
require 'pp'
pp res.headers
puts '=' * 80
puts res.body
exit
end
end
def dump_cotweet_agents(http, dir)
res = http.get
if res.status == 200
agents = {}
data = JSON.parse res.body
data['channels'].each do |channel|
channel['agents'].each do |agent|
agents[agent['id']] = agent
end
end
File.open File.join(dir, "agents.json"), 'w' do |io|
io << agents.to_json
end
else
require 'pp'
pp res.headers
puts '=' * 80
puts res.body
exit
end
end
http = Faraday.new 'http://standard.cotweet.com/api/1/timeline/sent.json'
http.params[:limit] = 100
http.basic_auth email, pass
dir ||= './cotweet'
dir = File.expand_path dir
item_dir = File.join(dir, 'items')
FileUtils.mkdir_p item_dir
dump_cotweet http, item_dir
http.path_prefix = "/api/1/channels/sources.json"
http.params.clear
dump_cotweet_agents http, dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment