Skip to content

Instantly share code, notes, and snippets.

@eban
Created March 24, 2011 08:24
Show Gist options
  • Save eban/884743 to your computer and use it in GitHub Desktop.
Save eban/884743 to your computer and use it in GitHub Desktop.
~/.earthquake/plugin/save-tweets.rb
# -*- coding: utf-8 -*-
require "fileutils"
require "time"
require "cgi"
Earthquake.init do
logdir = config[:logdir] || File.expand_path("~/.earthquake/log")
FileUtils.mkdir_p logdir
output do |item|
next unless item["_stream"] && item["text"]
created_at = Time.parse(item["created_at"]).strftime("%X")
open(File.join(logdir, Time.now.strftime("%F.log")), "a") do |f|
case item["event"]
when "favorite", "unfavorite"
f.puts "#{created_at} [favorite] #{item["source"]["screen_name"]} => #{item["target"]["screen_name"]}: #{item["target_object"]["text"]}"
else
# p item
user = item["user"] || item["target"] || ""
text = item["text"] || ""
f.puts "#{created_at} #{user["screen_name"]}: #{CGI.unescapeHTML(text)}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment