Last active
August 29, 2015 14:00
-
-
Save tsux89/11109603 to your computer and use it in GitHub Desktop.
時間割bot(天気予報付き)
This file contains hidden or 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 'twitter' | |
require 'tweetstream' | |
# sample consumer keys are Twitter for iPhone. | |
ck = 'IQKbtAYlXLripLGPWd0HUA' | |
cs = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU' | |
at = '' | |
ats = '' | |
$host = Twitter::REST::Client.new do |config| | |
config.consumer_key = ck | |
config.consumer_secret = cs | |
config.access_token = at | |
config.access_token_secret = ats | |
end | |
$n = DateTime.now | |
#=begin | |
$tt = [["Sun", "", "2", "3", "4", "5", "6", "7"],["Monday", "地学基礎/化学基礎", "現代文", "政治経済", "英語理解", "世界史/日本史", "数学演習Ⅰ・Ⅱ", ""],["Tuesday", "生物基礎演習", "世界史/日本史", "地学基礎/化学基礎", "英語理解", "Power English 3", "数学演習Ⅰ・Ⅱ", "無し"],["Wednesday", "世界史/日本史", "古典", "体育", "体育", "数学演習Ⅰ・Ⅱ", "総合的な学習の時間", "無し"],["Thursday", "現代文", "英語理解", "古典", "地学基礎/化学基礎", "数学演習Ⅰ・Ⅱ", "Global Education 2", "政治経済"],["Friday", "Global Education 2", "体育", "政治経済", "英語理解", "古典", "Power English 3", "無し"],["Sat", "1", "2", "3", "4", "5", "6", "7"]] | |
#=end | |
=begin | |
$tt = [ | |
["Sunday", "", "", "", "", "", "", ""], | |
["Monday", "Geology / Chemistry", "Japanese", "Political Economy", "English Understanding", "World History / Japanese History", "Mathematics", ""], | |
["Tuesday", "Biology", "W / J History", "Geology / Chemistry", "English Understanding", "PE 3", "Mathematics", "LHR"], | |
["Wednesday", "W / J History", "Classical Japanese", "Physical Education", "Physical Education", "Mathematics", "Periods for Integrated Study", ""], | |
["Thursday", "Japanese", "English Understanding", "Classical Japanese", "Geology / Chemistry", "Mathematics", "GE 2", "Political Economy"], | |
["Friday", "GE 2", "Physical Education", "Political Economy", "English Understanding", "Classical Japanese", "PE 3", ""], | |
["Saturday", "", "", "", "", "", "", ""], | |
] | |
=end | |
def tweet(wday) | |
if wday < 1 || wday > 5 then | |
return "Today doesn't have any schedules." | |
end | |
twit = "\n" + "Timetable of " + $tt[wday][0] + "\n" + | |
"1st. " + $tt[wday][1] + "\n" + | |
"2nd. " + $tt[wday][2] + "\n" + | |
"3rd. " + $tt[wday][3] + "\n" + | |
"4th. " + $tt[wday][4] + "\n" + | |
"5th. " + $tt[wday][5] + "\n" + | |
"6th. " + $tt[wday][6] + "\n" + | |
"7th. " + $tt[wday][7] + "\n" | |
return twit | |
end | |
def getwday (str) | |
wday = -1 | |
if /(今日|本日)の時間割/ =~ str then | |
wday = Date.today.wday | |
end | |
if /(明日|翌日)の時間割/ =~ str then | |
wday = Date.today.wday + 1 | |
end | |
if /(日曜日|日曜)の時間割/ =~ str then | |
wday = 0 | |
end | |
if /(月曜日|月曜)の時間割/ =~ str then | |
wday = 1 | |
end | |
if /(火曜日|火曜)の時間割/ =~ str then | |
wday = 2 | |
end | |
if /(水曜日|水曜)の時間割/ =~ str then | |
wday = 3 | |
end | |
if /(木曜日|木曜)の時間割/ =~ str then | |
wday = 4 | |
end | |
if /(金曜日|金曜)の時間割/ =~ str then | |
wday = 5 | |
end | |
if /(土曜日|土曜)の時間割/ =~ str then | |
wday = 6 | |
end | |
return wday | |
end | |
TweetStream.configure do |config| | |
config.consumer_key = ck | |
config.consumer_secret = cs | |
config.oauth_token = at | |
config.oauth_token_secret = ats | |
config.auth_method = :oauth | |
end | |
client = TweetStream::Client.new | |
require 'weather_jp' | |
client.userstream do |status| | |
usr = status.user.screen_name | |
str = status.text | |
puts "#{usr}: #{str}" | |
wday = getwday(str) | |
if wday >= 0 && usr !~ /3nana_tt/ then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}", in_reply_to_status_id: status.id) | |
end | |
if str.start_with?("@3nana_tt tweet") && usr =~ /69/ then | |
puts "recognized" | |
a = str.split(" ", 3) | |
puts "deleted" | |
$host.update("#{a[2]}\n※管理人による遠隔ツイートです。") | |
puts "tweeted" | |
end | |
if /!TOMORROW SCHEDULE!/ =~ str then | |
wday = Date.today.wday + 1 | |
$host.update("#{tweet(wday)}") | |
end | |
wday = "" | |
if /sch mon/ =~ str then | |
wday = 1 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch tue/ =~ str then | |
wday = 2 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch wed/ =~ str then | |
wday = 3 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch tur/ =~ str then | |
wday = 4 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch fri/ =~ str then | |
wday = 5 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch sat/ =~ str then | |
wday = 6 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /sch sun/ =~ str then | |
wday = 0 | |
if /me/ =~ str then | |
$host.update("@#{usr}\n#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
elsif /everyone/ =~ str && usr =~ /69/ then | |
$host.update("#{tweet(wday)}\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast mon/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 1 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 2 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 3 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 4 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 5 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 6 then | |
wd = 2 | |
hi = "明後日" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast tue/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.today.wday == 1 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 2 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 3 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 4 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 5 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 6 then | |
wd = 3 | |
hi = "3日後" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast wed/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 1 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.today.wday == 2 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 3 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 4 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 5 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 6 then | |
wd = 4 | |
hi = "4日後" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast tur/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 1 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 2 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.todaクソy.wday == 3 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 4 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 5 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 6 then | |
wd = 5 | |
hi = "5日後" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast fri/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 1 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 2 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 3 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.today.wday == 4 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 5 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 6 then | |
wd = 6 | |
hi = "6日後" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast sat/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 1 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 2 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 3 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 4 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.today.wday == 5 then | |
wd = 1 | |
hi = "明日" | |
elsif Date.today.wday == 6 then | |
wd = 0 | |
hi = "今日" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /4cast sun/ =~ str then | |
if Date.today.wday == 0 then | |
wd = 0 | |
hi = "今日" | |
elsif Date.today.wday == 1 then | |
wd = 6 | |
hi = "6日後" | |
elsif Date.today.wday == 2 then | |
wd = 5 | |
hi = "5日後" | |
elsif Date.today.wday == 3 then | |
wd = 4 | |
hi = "4日後" | |
elsif Date.today.wday == 4 then | |
wd = 3 | |
hi = "3日後" | |
elsif Date.today.wday == 5 then | |
wd = 2 | |
hi = "明後日" | |
elsif Date.today.wday == 6 then | |
wd = 1 | |
hi = "明日" | |
end | |
if wd <= 4 then | |
www = WeatherJp.get(:kochi, wd) | |
if str =~ /me/ then | |
$host.update("@#{usr}\n#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
elsif str =~ /everyone/ && usr =~ /69/ then | |
$host.update("#{hi}の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
else | |
$host.update("@#{usr} ERROR: #{hi}の天気予報は取得に失敗しました。(注:5日後以降の天気予報は取得できません。)\n#{Time.now.strftime("%M%S")}") | |
end | |
end | |
if /(今日|本日|きょう)/ =~ str && /(天気|てんき)/ =~ str && str =~ /(教えて|おしえて|教えろ|おしえろ)/ then | |
www = WeatherJp.get(:kochi, :today) | |
$host.update("@#{usr}\n本日の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
if /(翌日|明日|あした)/ =~ str && /(天気|てんき)/ =~ str && str =~ /(教えて|おしえて|教えろ|おしえろ)/ then | |
www = WeatherJp.get(:kochi, :tomorrow) | |
$host.update("@#{usr}\n明日の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
if str =~ /(明後日|あさって)/ && /(天気|てんき)/ =~ str && str =~ /(教え|おしえ)/ then | |
www = WeatherJp.get(:kochi, :day_after_tomorrow) | |
$host.update("@#{usr}\n明後日の天気は#{www.forecast}です。\n最高気温は#{www.max_temp}℃です。\nまた、最低気温は#{www.min_temp}℃です。\n降水確率は#{www.rain}%です。\n#{Time.now.strftime("%M%S")}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment