beautifulpython
beautifulpython
RReactiflux
Created by beautifulpython on 8/2/2023 in #help-js
beautifulpython – 17-16 Aug 2
found this. will clean it up and voila
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce(
(obj, title, index) => ((obj[title] = values[index]), obj),
{}
);
});
};
const CSVToJSON = (data, delimiter = ',') => {
const titles = data.slice(0, data.indexOf('\n')).split(delimiter);
return data
.slice(data.indexOf('\n') + 1)
.split('\n')
.map(v => {
const values = v.split(delimiter);
return titles.reduce(
(obj, title, index) => ((obj[title] = values[index]), obj),
{}
);
});
};
6 replies
RReactiflux
Created by beautifulpython on 8/2/2023 in #help-js
beautifulpython – 17-16 Aug 2
step 1
let url = 'https://raw.githubusercontent.com/plotly/datasets/master/3d-scatter.csv';

(async () => {
let data = await fetch(url);
let response = await data.text();
console.log('response', response);
return response;
})();
let url = 'https://raw.githubusercontent.com/plotly/datasets/master/3d-scatter.csv';

(async () => {
let data = await fetch(url);
let response = await data.text();
console.log('response', response);
return response;
})();
6 replies
RReactiflux
Created by beautifulpython on 8/2/2023 in #help-js
beautifulpython – 17-16 Aug 2
diving in
6 replies
RReactiflux
Created by beautifulpython on 8/2/2023 in #help-js
beautifulpython – 17-16 Aug 2
d3.csv does this automagically.
6 replies
RReactiflux
Created by beautifulpython on 7/27/2023 in #help-js
✅ – ✅ – beautifulpython – 15-19 Jul 27
I think I will go with a proxy like ngnix
8 replies
RReactiflux
Created by beautifulpython on 7/27/2023 in #help-js
✅ – ✅ – beautifulpython – 15-19 Jul 27
thanks sir.
8 replies
RReactiflux
Created by beautifulpython on 7/25/2023 in #help-js
✅ – ✅ – beautifulpython – 19-38 Jul 25
the first drain call requires a POST instead of a GET
76 replies
RReactiflux
Created by beautifulpython on 7/25/2023 in #help-js
✅ – ✅ – beautifulpython – 19-38 Jul 25
let body = 'select *, now() from tpch.sf1.orders order by orderkey asc limit 3';
(async () => {
const orders = await drainTrino('http://localhost:8080/v1/statement', 'POST', body);
console.log('from root', orders)
})();

async function drainTrino(nextUri, verb, body) {
let option = {
method: verb,
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrerPolicy: "no-referrer",
body: body,
headers: {
'accept': 'application/json',
'Authorization': 'Basic root'
}
};

if (body) {
option.body = body
};

let response = await fetch(nextUri, option);
let d = await response.json();
let orders = [];
if (d.data && d.columns) {

orders = d.data.map(item => {
let o = {};
o["orderkey"] = item[0].toString();
o[`clerk`] = item[6];
o[`totalprice`] = item[3];
o[`orderdate`] = item[4];
return o;
})

}
if (d.nextUri) {
const nextOrders = await drainTrino(d.nextUri, 'GET')
return [...orders, ...nextOrders];
} else {
return orders
}
}
let body = 'select *, now() from tpch.sf1.orders order by orderkey asc limit 3';
(async () => {
const orders = await drainTrino('http://localhost:8080/v1/statement', 'POST', body);
console.log('from root', orders)
})();

async function drainTrino(nextUri, verb, body) {
let option = {
method: verb,
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrerPolicy: "no-referrer",
body: body,
headers: {
'accept': 'application/json',
'Authorization': 'Basic root'
}
};

if (body) {
option.body = body
};

let response = await fetch(nextUri, option);
let d = await response.json();
let orders = [];
if (d.data && d.columns) {

orders = d.data.map(item => {
let o = {};
o["orderkey"] = item[0].toString();
o[`clerk`] = item[6];
o[`totalprice`] = item[3];
o[`orderdate`] = item[4];
return o;
})

}
if (d.nextUri) {
const nextOrders = await drainTrino(d.nextUri, 'GET')
return [...orders, ...nextOrders];
} else {
return orders
}
}
76 replies
RReactiflux
Created by beautifulpython on 7/25/2023 in #help-js
✅ – ✅ – beautifulpython – 19-38 Jul 25
thanks so much @ghardin137 learned a lot. final product is here
76 replies