Skip to content

Instantly share code, notes, and snippets.

@fand fand/hatenablog.rb
Created Apr 18, 2016

Embed
What would you like to do?
Bitbar はてなブログPlugin
#!/usr/bin/env ruby
require 'net/http'
require 'rexml/document'
require 'time'
FEED = 'XXXXXXXXXXXXXXXX'
def get_entries()
res = Net::HTTP.get(URI(FEED))
doc = REXML::Document.new(res)
REXML::XPath.match(doc, '/feed/entry')
end
def output(entry)
title = entry.elements['title'].text
url = entry.elements['link'].attribute('href').value
updated = entry.elements['updated'].text
t = Time.parse(updated).strftime('%Y-%m-%d %H:%M:%S')
puts t + ' ' + title + ' | href=' + url
end
puts 'はてなブログ'
puts '---'
begin
get_entries.each { |entry| output(entry) }
rescue => e
puts '記事情報、取得できひんかった(◞‸◟) | color=red'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.