Created
January 3, 2014 04:30
-
-
Save kenjiskywalker/8232758 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'net/https' | |
require 'json' | |
require 'string-irc' | |
require 'time' | |
ika_url = 'http://localhost/privmsg' | |
ika_port = PORT | |
ika_channel = CHANNEL | |
def get_status(url) | |
@url = url | |
uri = URI.parse(@url) | |
https = Net::HTTP.new(uri.host, uri.port ) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
https.start { | |
response = https.get(uri.path) | |
@stat = JSON.parse(response.body) | |
} | |
return @stat | |
end | |
def create_message(status) | |
# @status['created_on'] => "2013-08-01T01:10:39Z" | |
@status = status | |
create_date = Time.parse(@status['created_on']) + Time.zone_offset('JST') | |
# "2013-08-01T10:10:39 JST" | |
create_date = create_date.strftime("%Y-%m-%dT%H:%M:%S JST") | |
message = "GitHub status:" + @status['status'] + " \"" + @status['body'] + "\" created_on " + create_date | |
return message | |
end | |
def post_status(url, port, message, ika_channel) | |
@url = url | |
@port = port | |
@message = message | |
@ika_channel = ika_channel | |
uri = URI.parse(@url) | |
http = Net::HTTP.new(uri.host, @port) | |
message_color = StringIrc.new(message).orange | |
post_body = "message=#{message_color}&channel=\##{ika_channel}" | |
http.start { | |
response = http.post(uri.path, post_body) | |
} | |
end | |
previous = nil | |
# while check and post | |
while true do | |
status = get_status('https://status.github.com/api/last-message.json') | |
message = create_message(status) | |
if not previous.nil? and previous != message | |
post_status(ika_url, ika_port, message, ika_channel) | |
end | |
previous = message | |
sleep 30 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment