Skip to content

Instantly share code, notes, and snippets.

@shokai
Created October 26, 2012 12:42
Show Gist options
  • Select an option

  • Save shokai/3958552 to your computer and use it in GitHub Desktop.

Select an option

Save shokai/3958552 to your computer and use it in GitHub Desktop.
気温が低いときに警告を出す
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'tw'
require 'json'
threshold = 20
client = Tw::Client.new
client.auth
tweets = client.user_timeline('shokai_log').sort{|a,b|
b.time <=> a.time
}.map{|m|
JSON.parse m.text rescue nil
}.select{|m|
m.kind_of? Hash and [Fixnum, Float].include? m["気温"].class
}
p tweets
temp = tweets[0]["気温"]
puts "現在の気温 #{temp}度"
system "saykana 'げんざいのきおん'"
sleep 0.5
system "saykana '#{temp.to_i}ど'"
if temp < threshold
sleep 0.5
system 'saykana おからだにさわりますよ'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment