Created
February 27, 2012 08:02
-
-
Save hagiyaki/1922412 to your computer and use it in GitHub Desktop.
翻訳してツイートするearthquake.gem plugin(MSのappidいる)
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 -*- | |
# trans tweet / earthquake plugin | |
# e.g. :trans おはよう => Good morning | |
# :trans fr おはよう => Bonjour | |
# 使えるらしい言語 | |
# ar bg zh-CHS zh-CHT cs da nl en et fi fr de el ht he | |
# hu id it ja ko lv lt no pl pt ro ru sk sl es sv th tr uk vi | |
# | |
# appid取得 http://www.bing.com/developers/appids.aspx | |
# | |
require 'net/http' | |
appid = "40桁ぐらいのappidいれるところ" | |
Earthquake.init do | |
command %r|^:trans\s*(\w+)*\s*(.*)$|, :as => :trans do |m| | |
from = "ja" | |
to = m[1] ? m[1] : "en" | |
puts(to+"で翻訳") | |
text = m[2] | |
h = Net::HTTP.new("api.microsofttranslator.com") | |
html = h.get("/V2/Http.svc/Translate?appid="+appid+"&from="+from+"&to="+to+"&text=#{text}") | |
mg = html.body.match(/>(.*)<\/string/) | |
input(mg[1]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment