Skip to content

Instantly share code, notes, and snippets.

@ustreamer-01647
Forked from taiyoh/myoutput.rb
Last active December 20, 2015 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustreamer-01647/6192639 to your computer and use it in GitHub Desktop.
Save ustreamer-01647/6192639 to your computer and use it in GitHub Desktop.
ツイートごとの区切り線「-----」行を削除
# -*- 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