Created
May 3, 2017 07:13
-
-
Save robinclart/ab93b7d0274d35a97d10fa2a8eed382e to your computer and use it in GitHub Desktop.
A small script to parse the holiday dates from BOT website
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
#!/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