diff --git a/bin/convert-csv-to-json.mjs b/bin/convert-csv-to-json.mjs new file mode 100644 index 0000000..7a305fd --- /dev/null +++ b/bin/convert-csv-to-json.mjs @@ -0,0 +1,45 @@ +import fetch from 'node-fetch'; + +process.stdin.resume(); +process.stdin.setEncoding('utf8'); +let input = []; +process.stdin.on('data', (data) => { + input.push(data); +}); + +const token = + '1234567812345678123456781234567812345678123456781234567812345678'; + +const hostname = 'http://localhost:3333'; +const headers = { 'Content-Type': 'application/json' }; + +process.stdin.on('end', async () => { + for (let event_line of input.join('').split('\n')) { + const [ + facebook_id = '', + location_name = '', + place_id = '', + name = '', + start = '', + ticket_url = '' + ] = event_line.split('¤'); + + let event = { + draft: false, + canceled: false, + facebook_id, + location_name, + place_id: Number(place_id), + name, + start: Number(start), + ticket_url + }; + + let res = await fetch(`${hostname}/events/?token=${token}`, { + method: 'POST', + body: JSON.stringify(event), + headers + }); + console.log(await res.text()); + } +}); diff --git a/bin/convert-json-to-csv.mjs b/bin/convert-json-to-csv.mjs new file mode 100644 index 0000000..a816586 --- /dev/null +++ b/bin/convert-json-to-csv.mjs @@ -0,0 +1,35 @@ +import events from './events.json' assert { type: 'json' }; + +const dl = '¤'; + +console.log( + `canceled${dl}created${dl}draft${dl}end${dl}facebook_id${dl}host${dl}id${dl}location${dl}name${dl}start${dl}ticket_url${dl}updated` +); + +events.forEach( + ({ + canceled, + created, + draft, + end, + facebook_id, + host, + id, + location, + name, + start, + ticket_url, + updated + }) => { + const line = `${canceled}${dl}${created}${dl}${draft}${dl}${end}${dl}${facebook_id}${dl}${host}${dl}${id}${dl}${location}${dl}${name}${dl}${start}${dl}${ticket_url}${dl}${updated}`; + + if (line.split(`${dl}`).length != 12) { + console.error(id, name); + return; + } + + console.log( + `${canceled}${dl}${created}${dl}${draft}${dl}${end}${dl}${facebook_id}${dl}${host}${dl}${id}${dl}${location}${dl}${name}${dl}${start}${dl}${ticket_url}${dl}${updated}` + ); + } +);