Skip to content

Instantly share code, notes, and snippets.

@ohac
Created March 9, 2012 10:35
Show Gist options
  • Save ohac/2006011 to your computer and use it in GitHub Desktop.
Save ohac/2006011 to your computer and use it in GitHub Desktop.
simple short output plugin for earthquake and notmailto
# encoding: UTF-8
require 'stringio'
Earthquake.init do
output :tweet do |item|
next unless item["text"]
info = []
if item["in_reply_to_status_id"]
info << "to #{id2var(item["in_reply_to_status_id"])}"
elsif item["retweeted_status"]
info << "of #{id2var(item["retweeted_status"]["id"])}"
end
id = id2var(item["id"])
text = (item["retweeted_status"] && item["truncated"] ? "RT @#{item["retweeted_status"]["user"]["screen_name"]}: #{item["retweeted_status"]["text"]}" : item["text"]).u
text.gsub!(/([☎´ω`—■■□◆◇⊂⊃※“”☆★…])/, '\1 ')
text.gsub!(/\s+/, ' ')
text = text.coloring(/@[0-9A-Za-z_]+/) { |i| color_of(i) }
text = text.coloring(/(^#[^\s]+)|(\s+#[^\s]+)/) { |i| color_of(i) }
text.gsub!(/https{0,1}:\/\/t\.co\/(\w+)/, '\1@t.co')
text = text.coloring(/[0-9A-Za-z\-.]+@t\.co/, :url)
mark = item["_mark"] || ""
screen_name = item["user"]["screen_name"]
status = [
"#{mark}" + "#{id}".c(:info),
"#{screen_name.c(color_of(screen_name))}",
"#{text}",
(item["user"]["protected"] ? "P".c(:notice) : nil),
info.join(' - ').c(:info)
].compact.join(" ")
puts status
end
end
@ohac
Copy link
Author

ohac commented Mar 9, 2012

Replace http://t.co/ABC to ABC@t.co
Very short.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment