Last active
January 19, 2024 14:43
-
-
Save tomiolah/ac63485ad7ffe62bc2c21234df502917 to your computer and use it in GitHub Desktop.
RMBGYSz aranymondasok osszesitve a szentiras.hu-rol vett igeversekkel
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
const moment = require('moment'); | |
const axios = require('axios').default; | |
const months = "januar februar marcius aprilis majus junius julius augusztus szeptember oktober november december".split( | |
" " | |
); | |
const getBibleVerse = async (ref) => { | |
const { data: html } = await axios.get( | |
`https://szentiras.hu/RUF/${ref.replace(" ", "")}`, | |
{ headers: { 'Access-Control-Allow-Origin': 'http://localhost:3000/' } }, | |
); | |
const res = html | |
.split("\n") | |
.map((v) => v.trim()) | |
.filter((v) => v.startsWith('<span class="text-muted numv"><sup>')) | |
.map((v) => v.replace('<span class="text-muted numv">', "")) | |
.map((v) => v.replace(/<sup>[0-9]+<\/sup><\/span>/g, "")) | |
.join(" "); | |
return `"${res}" ${ref}`; | |
}; | |
const getRef = async (date, format = "YYYY-MM-DD") => { | |
const d = moment(date, format); | |
if (d.day() !== 0) { | |
throw Error("Not a Sunday!"); | |
} | |
const { data: html } = await await axios.get( | |
`https://www.rmbgysz.ro/${d.year()}-${ | |
months[d.month()] | |
}-${d.date()}-vasarnap`, | |
{ headers: { 'Access-Control-Allow-Origin': 'http://localhost:3000/' } }, | |
); | |
const res = html | |
.split("\n") | |
.map((v) => v.trim()) | |
.filter((v) => v.startsWith('<div class="field-item even"><p>Bibliaóra:')); | |
const startArr = []; | |
return res[0] | |
.split("") | |
.reduce( | |
(p, c) => | |
((p.length > 0 && !p.includes(")")) || c === "(") ? [...p, c] : p, startArr, | |
) | |
.filter((v) => !["(", ")"].includes(v)) | |
.join(""); | |
}; | |
const OneDate = async (date) => ({ | |
date: date.format('YYYY-MM-DD'), | |
verse: await getBibleVerse(await getRef(date.format("YYYY-MM-DD"))), | |
}); | |
const sundays = (date, goal, acc) => { | |
if (goal(date)) { | |
return acc; | |
} | |
return sundays( | |
date.day() !== 0 ? date.add(1, 'day').clone() : date.add(7, 'days').clone(), | |
goal, | |
date.day() === 0 ? [...acc, date.clone()] : acc, | |
); | |
} | |
async function main() { | |
const end = (date) => date.year() === 2022; | |
const sds = sundays(moment(), end, []); | |
await Promise.all(sds.map((s, i) => setTimeout(async () => console.log(await OneDate(s)), i * 1000))); | |
} | |
main(); |
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
{ | |
"name": "rmbgysz-aranymodas-getter", | |
"version": "1.0.0", | |
"description": "", | |
"main": "main.js", | |
"dependencies": { | |
"axios": "^0.21.0", | |
"moment": "^2.29.1" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"start": "node main.js" | |
}, | |
"author": "Olah Tamas", | |
"license": "WTFPL" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO
Address this reference: https://www.rmbgysz.ro/2021-december-26-vasarnap