悪のコード
code:seigadai.rb
require 'net/http'
require 'json'
BASE = 'https://www.opencheongwadae.kr/eng/reservation/previewList?standardDate='
def notify(datetime)
system %(osascript -e 'display notification "#{datetime}" with title "空き発見!!!!" sound name "Glass"')
end
while true do
puts "Checking availability at #{Time.now}...\n"
dates = %w(20250718 20250719 20250720 20250721 20250723)
dates.each do |date|
puts "Checking availability for #{date}..."
url = "#{BASE}#{date}"
response = Net::HTTP.get(URI(url))
data = JSON.parse(response)
puts data
data.each do |slot|
if slot'reservationCnt' > 0
puts "!!!!!! found !!!!!!!!!!"
notify("#{date} #{slot'visitstarttime'} left #{slot'reservationCnt'} slots!!!!")
end
end
sl = rand(1..3)
puts "Sleeping for #{sl} seconds..."
sleep(sl)
end
sl = rand(250..400)
puts "Sleeping for #{sl} seconds before next check..."
sleep(sl)
end
binding.irb