Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

羽田空港の駐車場の予約キャンセルをいち早く検知するスクリプト

More than 5 years have passed since last update.

羽田空港の駐車場予約がかなり激戦なので作りました。
ほんとどうでもいい内容なので、ソースだけのせて終了します。

require 'open-uri'
require 'nokogiri'

@reserve_days = [28, 29, 30]

def reserved_dai2ordai3?(doc, parking_num, day) 
    index = 0
    if parking_num == 2
        index = 1 #td index
    elsif parking_num == 3
        index = 3 #td index
    end
    doc.css("#guide_01 table tr")[2].css("td")[index].css(".calday").each do |dom| 
        if dom.text == "#{day}"
            return dom.attribute("class").value.include?("bgRed")
        end
    end
end

def reserved_dai4?(doc, day) 
    doc.css("#calendar01 table.calendar_waku td").each do |dom| 
        if dom.text == "#{day}"
            return dom.attribute("class").value.include?("full")
        end
    end
end

def can_reserve?(parking_num, days)
    if parking_num == 4 
        doc = make_doc('https://haneda-p4.jp/airport/entrance/0000.jsf')
        days.each do |day|
            if reserved_dai4?(doc, day)
                return false
            end
        end 
    else
        doc = make_doc('https://hnd-rsv.aeif.or.jp/airport/entrance/0000.jsf')
        days.each do |day|
            if reserved_dai2ordai3?(doc, parking_num, day)
                return false
            end
        end 
    end
    return true
end

def make_doc(url)
    charset = nil
    html = open(url) do |f|
      charset = f.charset
      f.read
    end

    doc = Nokogiri::HTML.parse(html, nil, charset)
end

# dai2
p can_reserve?(2, @reserve_days)

# dai3
p can_reserve?(3, @reserve_days)

# dai4
p can_reserve?(4, @reserve_days)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away