Created
February 22, 2014 03:15
-
-
Save vincenting/9148126 to your computer and use it in GitHub Desktop.
虾米自动签到 beta
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
| require 'patron' | |
| require 'rufus-scheduler' | |
| #TODO 异常触发后,将异常的具体内容通过邮件发送至管理员 | |
| module XiaMi | |
| @login_url = 'http://www.xiami.com/web/login' | |
| @index_url = 'http://www.xiami.com/web' | |
| @sign_url = 'http://www.xiami.com/web/checkin/id/' | |
| @sess = Patron::Session.new | |
| @sess.timeout = 10 | |
| @sess.handle_cookies | |
| @sess.insecure = true | |
| @sess.connect_timeout = 10 | |
| @sess.headers['User-Agent'] = 'Opera/9.60' | |
| @sess.headers['Referer'] = 'http://www.xiami.com/web' | |
| module_function | |
| def sign_in_id | |
| begin | |
| index_page = @sess.get @index_url | |
| index_page.body.split('/web/checkin/id/')[1].split('">')[0] | |
| rescue | |
| #TODO 触发已签到异常 | |
| nil | |
| end | |
| end | |
| def login(email, password) | |
| begin | |
| @sess.post(@login_url, { | |
| email: email, password: password, remember: 1, LoginButton: '登录' | |
| }, {'Content-Type' => 'application/x-www-form-urlencoded'}) | |
| #TODO 需要判断返回内容是否是登录成功,否则触发登录失败异常 | |
| rescue | |
| #TODO 触发登录失败异常 | |
| return nil | |
| end | |
| true | |
| end | |
| def sign_in | |
| begin | |
| sign_url = "#{@sign_url}#{sign_in_id}" | |
| puts sign_url | |
| @sess.get sign_url | |
| rescue | |
| #TODO 触发签到失败异常 | |
| nil | |
| end | |
| end | |
| end | |
| xiami_accounts = [ | |
| { | |
| email: '[email protected]', | |
| password: 'xxx' | |
| } | |
| ] | |
| if $0 == __FILE__ | |
| scheduler = Rufus::Scheduler.new | |
| scheduler.every '24h' do | |
| xiami_accounts.each do |account| | |
| # TODO 随机睡眠时间需要加入 | |
| XiaMi.login account[:email], account[:password] | |
| XiaMi.sign_in | |
| end | |
| end | |
| scheduler.join | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment