同人活動でIT業界をネタにしたカードゲームを作ってます。
2009-06-05
Spymasterで経験値稼ぎスクリプト
twitterアカウントを使って遊ぶゲーム、Spymasterに招待されたので始めてみた。なんかトラビアンに続く時間泥棒ゲームの予感がしたので、経験値稼ぎにタスクをこなすだけのスクリプトをrubyで書いた。
Spymaster ― For your eyes only.
http://playspymaster.com/
多重ログインを許しているみたいなので、firefoxで認証して取得したcookieをそのまま使えばMechanizeでも認証クリアできる。
require 'rubygems' require 'time' require 'mechanize' require 'nokogiri' require 'hpricot' require 'yaml' require 'json' def log(msg) puts Time.new.to_s + ' ' + msg end log "start()" begin uri = URI.parse('http://playspymaster.com/tasks') agent = WWW::Mechanize.new agent.user_agent_alias = 'Mac Safari' ###################################### # login to spymaster ###################################### auth_cookie = '_spymaster_session=$ブラウザが送信してるのと同じcookie$' WWW::Mechanize::Cookie.parse(uri, auth_cookie, nil){|c| agent.cookie_jar.add(uri, c) } task_page = agent.get(uri) doc_html = Nokogiri::HTML(task_page.body) # energyの取得 energy = 0 doc_html.css('#mini-dashboard-energy span.value').each do |val| energy = val.content end ###################################### # execute task ###################################### AUTH_TOKEN = "$spymasterのページのHTML中に記述されてるのをそのまま$" TASK = "assassinate_ambassador" TIME = "80" # 適当 if energy.to_i > 30 agent.post('http://playspymaster.com/tasks/perform',{"task" => TASK, "authenticity_token" => AUTH_TOKEN, "time" => TIME}) else # Energyが30以下の時は何もしない log "not enough energy:" + energy.to_s end rescue Exception => exp log "Abnormaly ended" log exp.to_s ensure #NOP end log "end()"
ログのファイル出力は余計だったので消しました。
タスク実行時に送信するパラメータは次の3つ
- task : タスク
- authenticity_token : 認証トークン
- time : リロードからの経過時間(?)
timeは適当に、認証トークンはHTML中に記述されていて、毎回変化が無いので固定値かもしれない。
とりあえず今夜からこれを5分毎に実行させておくので、仕事中にこっそりレベル上げをする必要は無さそうだ。
トラックバック - http://d.hatena.ne.jp/hagino_3000/20090605/1244133560
リンク元
- 17 http://reader.livedoor.com/reader/
- 11 http://d.hatena.ne.jp/
- 11 http://twitter.com/hagino_3000
- 6 http://b.hatena.ne.jp/entrylist?sort=hot&url=http://d.hatena.ne.jp/
- 6 http://twitter.com/
- 5 http://b.hatena.ne.jp/entrylist
- 5 http://www.google.co.jp/reader/view/
- 4 http://b.hatena.ne.jp/entry/http://d.hatena.ne.jp/hagino_3000/20090605/1244133560
- 4 http://b.hatena.ne.jp/entrylist/it
- 4 http://b.hatena.ne.jp/tyoro1210/20090605
おとなり日記
- 2009-06-02 医者を志す妻を応援する夫の日記 7/60 11%
- 2009-05-31 Cyokodog::Diary 6/82 7%
- 2009-06-04 iDeaList::Writing 6/101 5%