Last active
December 19, 2015 03:58
-
-
Save taiyoh/5893588 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
# my output settings | |
# 出力方法をこちらで決定する | |
Earthquake.init do | |
output :tweet do |item| | |
next unless item["text"] | |
info = [] | |
if item["in_reply_to_status_id"] | |
info << "(reply to #{id2var(item["in_reply_to_status_id"])})" | |
elsif item["retweeted_status"] | |
info << "(retweet of #{id2var(item["retweeted_status"]["id"])})" | |
end | |
if !config[:hide_time] && item["created_at"] | |
info << Time.parse(item["created_at"]).strftime(config[:time_format]) | |
end | |
if !config[:hide_app_name] && item["source"] | |
info << (item["source"].u =~ />(.*)</ ? $1 : 'web') | |
end | |
id = id2var(item["id"]) | |
text = (item["retweeted_status"] ? "RT @#{item["retweeted_status"]["user"]["screen_name"]}: #{item["retweeted_status"]["text"]}" : item["text"]).u | |
if config[:raw_text] && /\n/ =~ text | |
text.prepend("\n") | |
text.gsub!(/\n/, "\n " + "|".c(:info)) | |
text << "\n " | |
else | |
text.gsub!(/\s+/, ' ') | |
end | |
text = text.coloring(/@[0-9A-Za-z_]+/) { |i| color_of(i) } | |
text = text.coloring(/(^#[^\s]+)|(\s+#[^\s]+)/) { |i| color_of(i) } | |
if config[:expand_url] | |
entities = (item["retweeted_status"] && item["truncated"]) ? item["retweeted_status"]["entities"] : item["entities"] | |
if entities | |
entities.values_at("urls", "media").flatten.compact.each do |entity| | |
url, expanded_url = entity.values_at("url", "expanded_url") | |
if url && expanded_url | |
text = text.sub(url, expanded_url) | |
end | |
end | |
end | |
end | |
text = text.coloring(URI.regexp(["http", "https"]), :url) | |
if item["_highlights"] | |
item["_highlights"].each do |h| | |
color = config[:color][:highlight].nil? ? color_of(h).to_i + 10 : :highlight | |
text = text.coloring(/#{h}/i, color) | |
end | |
end | |
mark = item["_mark"] || "" | |
name_line = " #{item["user"]["screen_name"]} (#{item["user"]["name"]})".c(color_of(item["user"]["screen_name"])) | |
status = [ | |
"#{mark}" + "[#{id}]".c(:info) + name_line + " " + info.join(' - ').c(:info), | |
"#{text}" + (item["user"]["protected"] ? " [P]".c(:notice) : ""), | |
"-----".c(:info) | |
].compact.join("\n") | |
puts status | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment