Last active
November 19, 2022 15:36
-
-
Save lcllarsen/4f2dc46198e60bfa1c5c2c7014c20092 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 csv = require('fast-csv'); | |
const xml = require("js2xmlparser"); | |
const fs = require('fs'); | |
const doc = []; | |
const options = { | |
declaration:{ | |
include: false | |
} | |
} | |
const stream = fs.createReadStream("input.csv"); | |
csv | |
.fromStream(stream, {delimiter : ';', headers: true}) | |
.on("data", function(data){ | |
let name = data.name; | |
let content = data.content; | |
let review_url = data.review_url; | |
let rating = data.rating; | |
let product_url = data.product_url; | |
let review_timestamp = data.review_timestamp; | |
let obj = { | |
"reviewer": { | |
"name": name | |
}, | |
"review_timestamp": review_timestamp, | |
"content": content, | |
"review_url": { | |
"@": { | |
"type": "singleton" | |
}, | |
"#": review_url | |
}, | |
"ratings": { | |
"overall": { | |
"@": { | |
"min": 1, | |
"max": 5 | |
}, | |
"#": rating | |
} | |
}, | |
"products": { | |
"product": { | |
"product_url": product_url; | |
} | |
} | |
}; | |
doc.push(obj); | |
}) | |
.on("end", function(){ | |
doc.forEach(function(row){ | |
fs.appendFile('output.xml', xml.parse("review", row, options) + '\n', 'utf-8', (err) => { | |
if (err) throw err; | |
}); | |
}); | |
fs.appendFile('output.xml', "</reviews></feed>", (err) => { | |
if(err) throw err; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I tried to add this code to my Shopify store, by adding a new .js file in Assets but I can't see if it works...
What is the xml URL?
My codding knowledge is very limited.
Thank you.