Created
January 9, 2017 10:40
-
-
Save watsy0007/388534d9e7d1b5ae7c1ce0e09014552d 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
# -*- coding: utf-8 -*- | |
require 'uri' | |
require 'net/http' | |
require 'json' | |
require 'byebug' | |
require 'pp' | |
def request(url) | |
req ||= Net::HTTP::Post.new url | |
req["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' | |
req["cache-control"] = 'no-cache' | |
req.body = "" | |
req | |
end | |
def response(http, url) | |
resp = http.request request(url) | |
JSON.parse resp.read_body | |
end | |
def monitor | |
url = URI("http://interfaces.ziroom.com/index.php?_p=api_mobile&_a=detailShow&city_code=110000") | |
http = Net::HTTP.new(url.host, url.port) | |
index = 0 | |
now = Time.now | |
loop do | |
json = response http, url | |
if json['data'][0]['house_status'] == 'tzpzz' | |
puts '退租配置中' | |
elsif json['data'][0]['house_status'] == 'sfz' | |
second = json['data'][0]['sign_date'] | |
puts "#{second / 60}:#{second % 60} s" | |
else | |
exit 1 | |
end | |
puts "焦急等待中 #{Time.now - now}" if (index % 10).zero? | |
sleep(rand(10) + 10) | |
index += 1 | |
end | |
end | |
monitor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment