Created
March 22, 2012 05:04
-
-
Save jugyo/2156204 to your computer and use it in GitHub Desktop.
aview earthquake.gem plugin
This file contains hidden or 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 | |
require 'open-uri' | |
require 'tmpdir' | |
Earthquake.init do | |
command :aview do |m| | |
if m[1] =~ /^http/ | |
url = m[1] | |
else | |
url = twitter.show(m[1])["profile_image_url"] | |
end | |
Dir.mktmpdir do |dir| | |
source = File.join(dir, File.basename(url)) | |
dest = File.join(dir, 'dest.pnm') | |
File.open(source, 'wb') {|f| f << open(url).read} | |
begin | |
(system 'convert', source, dest) || (raise 'Faild to execute `convert`. Please install ImageMagick.') | |
(system 'aview', '-driver', 'curses', dest) || (raise 'Faild to execute `aview`. Please install Aview.') | |
rescue => e | |
puts e.message | |
end | |
end | |
end | |
help :aview, "Show image as text using Aview", <<-HELP | |
⚡ :aview http://example.com/image.jpg | |
⚡ :aview jugyo | |
HELP | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment