Last active
January 7, 2020 08:52
-
-
Save christianhaller3000/9612c94d37472854491ddb64c94427d0 to your computer and use it in GitHub Desktop.
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 fetch = require("node-fetch"); | |
const fn = async () => { | |
const token = "11e01fc60358e3d96947ab6d4afaee66"; | |
const today = new Date().toDateString(); | |
const iconMap = { | |
"10": "Ⓥ", | |
"11": "🌱", | |
"12": "🌾", | |
"13": "🚫🥛", | |
"16": "🐟", | |
"17": "🐓" | |
}; | |
const res = await fetch( | |
`https://kochwerk-web.webspeiseplan.de/index.php?token=${token}&model=menu&location=1800&languagetype=1&_=1578318310364`, | |
{ | |
headers: { | |
referer: "https://kochwerk-web.webspeiseplan.de/Menu" | |
} | |
} | |
); | |
const { content } = await res.json(); | |
content | |
.sort((a, b) => { | |
if (a.speiseplanGerichtData.length < b.speiseplanGerichtData.length) { | |
return 1; | |
} | |
if (a.speiseplanGerichtData.length > b.speiseplanGerichtData.length) { | |
return -1; | |
} | |
return 0; | |
}) | |
.forEach((outlet) => { | |
const { anzeigename } = outlet.speiseplanAdvanced; | |
const mealsToday = outlet.speiseplanGerichtData.filter((gericht) => { | |
return ( | |
new Date( | |
Date.parse(gericht.speiseplanAdvancedGericht.datum) | |
).toDateString() === today | |
); | |
}); | |
if (mealsToday.length > 2) { | |
console.log(`\n 🏢️ ${anzeigename} (${today})\n`); | |
mealsToday.forEach( | |
({ gerichtmerkmaleIds, speiseplanAdvancedGericht }) => { | |
let icons = " "; | |
if (gerichtmerkmaleIds) { | |
icons = gerichtmerkmaleIds | |
.split(",") | |
.map((id) => { | |
return iconMap[id] || id; | |
}) | |
.join(" "); | |
} | |
const gerichtName = speiseplanAdvancedGericht.gerichtname | |
.replace(/(\r\n|\n|\r)/gm, " ") | |
.replace(/ +/g, " ") | |
.replace("Kleine Portion 1,50 €", "") | |
.replace("kleine Portion 1,50€", "") | |
.replace("Kleine Portion 1,50€", ""); | |
console.log(`• ${gerichtName} ${icons}`); | |
} | |
); | |
} | |
}); | |
}; | |
fn(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment