Created
June 13, 2022 03:11
-
-
Save evianzhow/aa3375b28c607e6058c8e82fea980d50 to your computer and use it in GitHub Desktop.
山姆下单监控小程序版(Updated:22/4/12)
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 'net/http' | |
require 'net/https' | |
require 'json' | |
def t_puts(*args) | |
print Time.now.strftime("[%Y-%m-%d %H:%M:%S] ") | |
puts *args | |
end | |
# Request (POST ) | |
def send_request | |
uri = URI('https://api-sams.walmartmobile.cn/api/v1/sams/delivery/portal/getCapacityData') | |
# Create client | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
dict = { | |
"appId" => "wxb344a8513eaaf849", | |
"storeDeliveryTemplateId" => "552578721878546198", | |
"uid" => "REPLACE_YOUR_UID", | |
"perDateList" => [ | |
# PLEASE CHANGE BELOW | |
"2022-04-12", | |
"2022-04-13", | |
"2022-04-14", | |
"2022-04-15", | |
"2022-04-16", | |
"2022-04-17", | |
"2022-04-18" | |
], | |
"saasId" => "1818" | |
} | |
body = JSON.dump(dict) | |
# Create Request | |
req = Net::HTTP::Post.new(uri) | |
# Add headers | |
req.add_field "auth-token", "REPLACE_YOURS_AUTH_TOKEN" | |
# Add headers | |
req.add_field "device-type", "mini_program" | |
# Add headers | |
req.add_field "Accept-Encoding", "gzip, deflate, br" | |
# Add headers | |
req.add_field "Accept-Language", "en-us" | |
# Add headers | |
req.add_field "Content-Type", "application/json;charset=utf-8" | |
# Add headers | |
req.add_field "Content-Length", "221" | |
# Add headers | |
req.add_field "User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E217 MicroMessenger/6.8.0(0x16080000) NetType/WIFI Language/en Branch/Br_trunk MiniProgramEnv/Mac" | |
# Add headers | |
req.add_field "Connection", "keep-alive" | |
# Add headers | |
req.add_field "system-language", "CN" | |
# Add headers | |
req.add_field "Referer", "https://servicewechat.com/wxb344a8513eaaf849/228/page-frame.html" | |
# Add headers | |
req.add_field "Cookie", "auth-token=" | |
# Set body | |
req.body = body | |
# Fetch Request | |
res = http.request(req) | |
t_puts "Response HTTP Status Code: #{res.code}" | |
#puts "Response HTTP Response Body: #{res.body}" | |
res | |
rescue StandardError => e | |
t_puts "HTTP Request failed (#{e.message})" | |
nil | |
end | |
def every_so_many_seconds(seconds) | |
last_tick = Time.now | |
loop do | |
sleep 0.1 | |
if Time.now - last_tick >= seconds | |
last_tick += seconds | |
yield | |
end | |
end | |
end | |
every_so_many_seconds(3) do | |
res = send_request | |
if res != nil | |
res_json = JSON.parse(res.body) | |
capcityResponseList = res_json['data']['capcityResponseList'] | |
next unless (capcityResponseList || []).length > 0 | |
capcityResponseList.each { |cap| | |
next if cap['dateISFull'] == true | |
t_puts "#{cap['strDate']}" | |
(cap['list'] || []).filter { |x| x['timeISFull'] != true }.map { |x| | |
t_puts "#{x['startTime']}~#{x['endTime']}" | |
} | |
pid = spawn('`say "Sams Club timeslot now available!"`') | |
Process.detach(pid) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment