-
-
Save hosseinmasoomi/0d5f873ec54e5538d3f46264c82d4126 to your computer and use it in GitHub Desktop.
api persian - shamsi calendar - holidays
This file contains hidden or 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
Array.from(document.querySelectorAll("li[class='eventHoliday ']"), (node => ({ | |
date:document.querySelector("input[type='text']").value +'/' + (Array.from(document.querySelectorAll("div[class='col-md-12']>div>div>span>span>span"), node => node.innerText).findIndex(x => x === node.innerText.split(" ")[1]) + 1).toString() + "/" + node.innerText.split(" ")[0].replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d)), | |
description: node.innerText.split(" ").slice(2).join(" ") | |
}))) |
Thanks a lot!
(() => {
const persianDigits = '۰۱۲۳۴۵۶۷۸۹';
const faToEn = s => s.replace(/[۰-۹]/g, d => persianDigits.indexOf(d));
const year = document.querySelector("input[type='text']")?.value ?? "1404";
const monthElements = Array.from(document.querySelectorAll("div.col-md-12 > div > div > span > span > span"));
const monthNames = monthElements.map(el => el.innerText.trim());
const holidays = Array.from(document.querySelectorAll("li.eventHoliday")).map(node => {
const parts = node.innerText.trim().split(/\s+/);
if (parts.length < 3) return null;
const day = faToEn(parts[0]);
const monthName = parts[1];
const desc = parts.slice(2).join(" ");
const monthIndex = monthNames.findIndex(x => x === monthName) + 1;
return {
date: `${year}/${monthIndex}/${day}`,
description: desc
};
}).filter(Boolean);
console.log(JSON.stringify(holidays, null, 2));
copy(holidays);
})();
I think this is easiest way to get JSON output of the holidays. Just run the code on console of the target URL ( you can also select another year and get the data from it! ), maybe this helps...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx for clarifying