Skip to content

Instantly share code, notes, and snippets.

@lilianalillyy
Last active May 26, 2025 09:09
Show Gist options
  • Save lilianalillyy/f895824c108f6560495614fa3f9eb4a4 to your computer and use it in GitHub Desktop.
Save lilianalillyy/f895824c108f6560495614fa3f9eb4a4 to your computer and use it in GitHub Desktop.
Moneta Table Export

While Moneta supports data exports in CSV, some places (like card blocks) cannot be exported. This script parses the table's HTML and allows you to read your data programmatically, export it as json or csv.

Usage:

// any variable name can be used
const table = /*<contents of script>*/

table.data // parsed data
table.csv(delimiter = ",") // returns data as CSV
table.json(indentation = 2) // returns data as JSON
table.download("csv" | "json", ...parameters) // downloads file in specified format, accepts same parameters in same order as the methods above
(() => {
const data = [...document.querySelectorAll(".c-contentTable tbody tr")].map(row => {
const title = row.querySelector("td h2.c-contentTableRow__title")?.textContent
?.split(" ")
// Remove redundant spaces
.map(s => s.trim())
.filter(s => !!s.length)
.join(" ") ?? null;
const date = row.querySelector("td .c-contentTableRow__subtitle small")?.textContent
// date | label -> date
?.split(" | ")?.[0]
// remove spaces
?.replaceAll(" ", "").split(".")
// parse all date parts as number, subtract 1 from month (months start from 0)
.map((part, i) => { part = Number(part); if (i == 1) { part-- }; return part; }).reverse() ?? null;
// remove currency (hardcoded " CZK" - 4 characters)
let price = [row.querySelector("td .t-amount")?.textContent]
// array hack so i don't have to reassign variable
.map(price => price?.substring(0, (price?.length ?? 0) - 4))[0]
?.replaceAll(" ", "")
.replaceAll(" ", "")
.replaceAll(",", ".") ?? null;
return { title, date: date ? new Date(...date) : null, price: price ? Number(price) : null };
})
return {
data,
csv(delimiter = ",") {
const csv = [
["Položka","Datum","Cena"].join(delimiter),
...data.map(({title, date, price}) => [`"${title}"`, date.toLocaleDateString("cs-CZ"), price].join(delimiter))
].join("\n");
return {
type: "text/csv",
data: csv,
};
},
json(indentation = 2) {
const json = JSON.stringify(data, null, indentation);
return {
type: "application/json",
data: json,
}
},
download(type, ...parameters) {
if (!this[type]) {
console.error("nu uh")
return;
}
const { type, data } = this[type](...parameters);
const blob = new Blob([data], { type });
window.open(URL.createObjectURL(blob));
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment