Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@robinclart
Created May 3, 2017 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinclart/ab93b7d0274d35a97d10fa2a8eed382e to your computer and use it in GitHub Desktop.
Save robinclart/ab93b7d0274d35a97d10fa2a8eed382e to your computer and use it in GitHub Desktop.
A small script to parse the holiday dates from BOT website
#!/usr/bin/env ruby
require "mechanize"
require "nokogiri"
require "date"
require "json"
agent = Mechanize.new
page = agent.get("https://www.bot.or.th/English/FinancialInstitutions/FIholiday/Pages/2017.aspx")
document = Nokogiri(page.body.to_s)
rows = document.css("#MSOZoneCell_WebPartWPQ2 .ms-rtestate-field .bot-rteTable-mytable2 tr")
dates = rows.map do |row|
cells = row.css("td")
weekday = cells[1].text.strip
day = cells[2].text.gsub(/[^\d]/, "").to_i
month = cells[3].text
year = 2017
desc = cells[4].text
date = Date.parse("#{weekday} #{day} #{month} #{year}")
date.iso8601
end
puts JSON.pretty_generate(dates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment