Created
October 4, 2010 10:25
-
-
Save hisasann/609489 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
require "rubygems" | |
require "twitter" | |
require "date" | |
class Kinenter | |
@@prefix_msg = [ | |
"おいら", | |
"わたし", | |
"私", | |
"ぼく", | |
"僕", | |
"おいどん", | |
"小生", | |
"ワタクシ", | |
"Me" | |
] | |
@@suffix_msg = [ | |
"しました。", | |
"したっちゃ。", | |
"したでゴワス!", | |
"しましたけど、何か?", | |
"したよ。グヘヘ…", | |
"した。頑張りました!", | |
"しました。エライわ〜。" | |
] | |
def initialize() | |
end | |
def post_date(map, start_date) | |
tw_oauth = Twitter::OAuth.new(map.fetch("c-key"), map.fetch("c-secret")) | |
tw_oauth.authorize_from_access(map.fetch("a-token"), map.fetch("a-token-secret")) | |
twit = Twitter::Base.new(tw_oauth) | |
# p make_message(start_date) # debug | |
twit.update(make_message(start_date)) | |
end | |
def make_message(start_date) | |
day = get_passage_of_time(start_date) | |
return @@prefix_msg[rand(@@prefix_msg.length)] + "が禁煙し始めてから " + day + " 日が経過" + @@suffix_msg[rand(@@suffix_msg.length)] + " #kinentter #kinen" | |
end | |
def get_passage_of_time(start_date) | |
date = start_date.split("/") | |
day1 = Time.local(date[0], date[1], date[2], 0, 0, 0) | |
day2 = Time.now | |
days = (day2 - day1).divmod(24*60*60) | |
return "#{days[0].to_i}" | |
end | |
end | |
Kinenter.new().post_date({ | |
"c-key" => "XXXX", | |
"c-secret" => "XXXX", | |
"a-token" => "XXXX", | |
"a-token-secret" => "XXXX" | |
}, "2010/10/03") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment