Spaces:
Running
Running
add BTC moon, add more markets, change dots status logic, change tradingview plugins into screenshot pictures,
78fdef7 Download scripts/generate_holidays.js from thonguyen511/Heatmap: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/thonguyen511/Heatmap/resolve/main/scripts/generate_holidays.js
- Command line
-
hf download hf://spaces/thonguyen511/Heatmap/scripts/generate_holidays.js
-
curl -L -o generate_holidays.js https://huggingface.co/spaces/thonguyen511/Heatmap/resolve/main/scripts/generate_holidays.js
1.16 kB
| const fs = require('fs'); | |
| const path = require('path'); | |
| const Holidays = require('date-holidays'); | |
| const marketsPath = path.join(__dirname, '../assets/geo/markets.json'); | |
| const outputPath = path.join(__dirname, '../assets/geo/holidays.json'); | |
| const year = new Date().getFullYear(); | |
| function generate() { | |
| const data = JSON.parse(fs.readFileSync(marketsPath, 'utf8')); | |
| const cache = {}; | |
| data.forEach(m => { | |
| const iso3 = m.iso; | |
| const iso2 = m.iso2; | |
| if (iso3 === 'EUR' || iso3 === 'EUN' || !iso2) { // Europe regions or missing iso2 | |
| cache[iso3] = []; | |
| return; | |
| } | |
| try { | |
| const hd = new Holidays(iso2); | |
| const list = hd.getHolidays(year); | |
| if (list) { | |
| cache[iso3] = list.filter(h => h.type === 'public').map(h => h.date.split(' ')[0]); | |
| } else { | |
| cache[iso3] = []; | |
| } | |
| } catch (e) { | |
| cache[iso3] = []; | |
| } | |
| }); | |
| fs.writeFileSync(outputPath, JSON.stringify(cache, null, 2)); | |
| console.log('Done generating holidays using iso2 from markets.json!'); | |
| } | |
| generate(); | |