Skip to content

Instantly share code, notes, and snippets.

@yamatema
Last active September 10, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamatema/b1f54793e02a303f7c79 to your computer and use it in GitHub Desktop.
Save yamatema/b1f54793e02a303f7c79 to your computer and use it in GitHub Desktop.
=begin
GITADORA Tri-boost のスキルポイント・全スキルポイント、プレーの有無を記録する
スキルポイント等は output.txt に、実行結果は log.txt に保存
=end
require 'mechanize'
require 'open-uri'
require 'nokogiri'
require 'date'
url_login = 'https://p.eagate.573.jp/gate/p/login.html'
url_data = 'http://p.eagate.573.jp/game/gfdm/gitadora_tb/p/eam/playdata/profile.html'
url_recentG = 'http://p.eagate.573.jp/game/gfdm/gitadora_tb/p/eam/playdata/stage_result.html?gtype=gf&stype='
url_recentD = 'http://p.eagate.573.jp/game/gfdm/gitadora_tb/p/eam/playdata/stage_result.html?gtype=dm&stype='
konami_id = '********'
konami_pass = '********'
date_now = Date.today
##########################################
# 1) KONAMI e-AMUSEMENT GATEへのログイン #
#########################################
agent = Mechanize.new
# 証明書無視して進む。よろしくないけどとりあえずこれ
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
agent.get(url_login)
agent.page.encoding = "utf-8" #このへんがよくわからない
form = agent.page.forms.first
form.field("KID").value = konami_id
form.field("pass").value = konami_pass
agent.submit(form, form.buttons.first)
#######################################################
# 2) 最新のスキルポイント・全スキルポイントを切り出す #
# また、最終プレー日時を切り出す #
######################################################
# GITADORA Tri-Boost のプレーデータのページへ移動
page = agent.get(url_data)
agent.page.encoding = "Shift-JIS"
# データを切り出してそれぞれ格納
now = {
"date" => date_now,
"skill_G" => page.search('td')[2].text.to_f, #GFスキルポイント
"skill_D" => page.search('td')[3].text.to_f, #DMスキルポイント
"skillA_G" => page.search('td')[5].text.to_f, #GF全スキルポイント
"skillA_D" => page.search('td')[6].text.to_f, #DM全スキルポイント
"playG" => false, #ギターをプレーしたかどうか
"playD" => false #ドラムをプレーしたかどうか
}
# プレー履歴のページ(GF)へ移動
page = agent.get(url_recentG)
agent.page.encoding = "Shift-JIS"
rec = page.search('//div[@class = "play_date"]').text.split
last_play_gf = Date.parse(rec[0])
# プレー履歴のページ(DM)へ移動
page = agent.get(url_recentD)
agent.page.encoding = "Shift-JIS"
rec = page.search('//div[@class = "play_date"]').text.split
last_play_dm = Date.parse(rec[0])
#######################################################
# 3) 直近のスキルポイント・全スキルポイントを切り出す #
######################################################
# 直近のスキルポイント・全スキルポイントを記録用ファイル output.txt の最終行から取り出す
last_line = String.new
File.open("output.txt") do |f|
f.each_line do |line|
last_line = line
end
end
# 比較用のハッシュへ
last_line.chomp!
a = last_line.split(/, /)
prev = {
"date" => Date.parse(a[0]),
"skill_G" => a[1].to_f,
"skill_D" => a[2].to_f,
"skillA_G" => a[3].to_f,
"skillA_D" => a[4].to_f,
}
#############################
# 4) 各種データの比較を行う #
############################
# スキルポイントが上がったか判定
up = {"gf" => false, "dm" => false, "gfA" => false, "dmA" => false}
up["gf"] = true if prev["skill_G"] < now["skill_G"]
up["dm"] = true if prev["skill_D"] < now["skill_D"]
up["gfA"] = true if prev["skillA_G"] < now["skillA_G"]
up["dmA"] = true if prev["skillA_D"] < now["skillA_D"]
# その日にギターおよびドラムをプレーしたかどうかを判定
# プレー履歴の直近のプレー日時と、実行時の日付が一致しているかで判断
now["playG"] = true if last_play_gf == now["date"]
now["playD"] = true if last_play_dm == now["date"]
###############################################################
# 5) スキルポイント・全スキルポイントの変化のしかたで場合分け #
##############################################################
# 書き込み用データの準備
final = {
"date" => now["date"],
"skill_G" => 0,
"skill_D" => 0,
"skillA_G" => 0,
"skillA_D" => 0,
"playG" => 0,
"playD" => 0
}
# GFおよびDMの全スキルポイントの変化パターン (4種) で場合分けし、
# GFおよびDMをプレーしたかどうか (playG,playD) を満たしていく
# 全スキルポイント変化パターン
# (A)両方上昇, (B)GFだけ上昇, (C)DMだけ上昇, (D)両方変化なし
if up["gfA"] == true && up["dmA"] == true #(A)
final["playG"] = 1
final["playD"] = 1
elsif up["gfA"] == true && up["dmA"] == false #(B)
final["playG"] = 1
final["playD"] = 1 if now["playD"] == true
elsif up["gfA"] == false && up["dmA"] == true #(C)
final["playG"] = 1 if now["playG"] == true
final["playD"] = 1
else #(D)
final["playG"] = 1 if now["playG"] == true
final["playD"] = 1 if now["playD"] == true
end
###############
# 6) 保存する #
##############
# GFもDMもプレーしていないときは記録しない
unless final["playG"] == 0 && final["playD"] == 0
final["skill_G"] = now["skill_G"].to_s
final["skill_D"] = now["skill_D"].to_s
final["skillA_G"] = now["skillA_G"].to_s
final["skillA_D"] = now["skillA_D"].to_s
final_line = "#{final["date"].strftime("%Y/%m/%d")}, "
final_line << "#{sprintf("%7.2f", final["skill_G"])}, "
final_line << "#{sprintf("%7.2f", final["skill_D"])}, "
final_line << "#{sprintf("%7.2f", final["skillA_G"])}, "
final_line << "#{sprintf("%7.2f", final["skillA_D"])}, "
final_line << "#{final["playG"].to_s}, " << "#{final["playD"].to_s}"
f = File.open("output.txt", "a")
f.puts final_line
f.close
f = File.open("log.txt", "a")
f.puts "#{Time.now.to_s} スキルポイントは正常に記録されました。"
f.close
else
f = File.open("log.txt", "a")
f.puts "#{Time.now.to_s} 両機種とも本日のプレー記録がなかったのでスキルポイントの記録は行いませんでした。"
f.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment