Skip to content

Instantly share code, notes, and snippets.

@rbrahul
Last active March 30, 2018 20:10
Show Gist options
  • Save rbrahul/4713f59683a4cd8fd720d76446200be5 to your computer and use it in GitHub Desktop.
Save rbrahul/4713f59683a4cd8fd720d76446200be5 to your computer and use it in GitHub Desktop.
Holiday Scrapper for Tanim vai :p
var holidays = [];
$(document).ready(function () {
$(".list-table").find("tbody").find("tr").each(function (index, item) {
var holiday = {};
$(item).find("td").each(function (indx, colunm) {
if (indx == 1) {
var timeTag = $(colunm).find("time");
var timeStamp;
var dateText;
if (timeTag.length) {
dateText = $.trim(timeTag.attr("datetime"));
timeStamp = (new Date(dateText)).getTime();
} else {
dateText = $.trim($(colunm).text());
dateText += dateText + " " + (new Date()).getFullYear()
timeStamp = (new Date(dateText)).getTime();
}
holiday["date"] = timeStamp;
} else if (indx == 2) {
holiday["title"] = $.trim($(colunm).text());
} else if (indx == 3) {
holiday["description"] = $.trim($(colunm).text());
}
holiday["type"] = "gov";
});
if (Object.keys(holiday).length > 1) {
holidays.push(holiday);
}
});
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(holidays, null, 2));
var link = document.createElement("a");
link.href = "data:" + data;
link.style = "visibility:hidden";
link.download = "Holidays.json";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment