Last active
December 19, 2015 07:19
-
-
Save Akkiesoft/5917705 to your computer and use it in GitHub Desktop.
ゆっくりたんのmikutter_rssを丸ごとパクり、haiku用に書き換えてみたもの。 URLはこれとかを指定したらいい http://h.hatena.ne.jp/api/statuses/public_timeline.json
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 -*- | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'time' | |
Plugin.create(:mikutter_haiku) do | |
def reload | |
#更新を行う | |
timeline(:mikutter_haiku).clear | |
(UserConfig[:haiku_url]|| []).select{|m|!m.empty?}.each do |url| | |
#パースに失敗する場合がある 失敗した場合は例外引っ掛けてスルー | |
begin | |
uri = URI.parse("#{url}?body_formats=haiku") | |
json = Net::HTTP.get(uri) | |
items = JSON.parse(json) | |
rescue => ee | |
timeline(:mikutter_haiku) << Message.new({ | |
:message => "JSONのパースに失敗しました\n#{url}?body_formats=haiku\n#{ee}", | |
:system => true | |
}) | |
else | |
#逆順にTLに入ってしまうので配列に代入してあとからTLに挿入 | |
#汚い | |
n=items.size | |
i=0 | |
while i<n do | |
#文章を整形 | |
keyword=items[n-i-1]['keyword'] | |
body =items[n-i-1]['haiku_text'] | |
link =items[n-i-1]['link'] | |
source =items[n-i-1]['source'] | |
user = User.new({ | |
:id => i+1, | |
:idname => items[n-i-1]['user']['screen_name'], | |
:name => items[n-i-1]['user']['name'], | |
:profile_image_url => items[n-i-1]['user']['profile_image_url'], | |
:url => items[n-i-1]['user']['url'] | |
}) | |
time = Time.parse(items[n-i-1]['created_at']) | |
timeline(:mikutter_haiku) << Message.new({ | |
:id => i+1, | |
:message => "<#{keyword}> #{body} #{link}", | |
:user => user, | |
:source => source, | |
:created => time | |
}) | |
i+=1 | |
end | |
end | |
end | |
end | |
btn = Gtk::Button.new('更新') | |
tab(:mikutter_haiku, 'はてなハイク') do | |
set_icon File.expand_path(File.join(File.dirname(__FILE__), 'logo.png')) | |
shrink | |
nativewidget Gtk::HBox.new(false, 0).closeup(btn) | |
expand | |
timeline :mikutter_haiku | |
end | |
#更新ボタン | |
btn.signal_connect('clicked'){ |elm| | |
reload | |
} | |
#1分に1度 自動で更新 | |
on_period do | |
if(UserConfig[:haiku_auto]) | |
reload | |
end | |
end | |
if(UserConfig[:haiku_exec]) | |
reload | |
end | |
settings "mikutter haiku" do | |
boolean('起動時に更新する', :haiku_exec) | |
boolean('1分毎に自動更新を行う', :haiku_auto) | |
multi "ハイクJSON URL", :haiku_url | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment