Created
October 20, 2020 09:24
-
-
Save pwfcurry/5aaccc4a74309d04b8defbf732d7ff18 to your computer and use it in GitHub Desktop.
Converts Sainsbury json receipt to csv
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
// node <this file.js> <sainsbury json receipt> | |
const fs = require("fs"); | |
const file = process.argv[2]; | |
const data = JSON.parse(fs.readFileSync(file, { encoding: "utf8", flag: "r" })); | |
console.log("name,qty,total"); | |
data.order_items.map(item => { | |
const name = item.product.name.replace(",", ""); | |
const adjustment = parseFloat(item.product.totalAdjustment.value); | |
const total = item.sub_total + adjustment; | |
console.log([name, item.quantity, total].join(",")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment