I`m pretty new to Scriptable as well as JS.
Does anyone know if there is a way to import data from a CSV in Scriptable?
I saw a lot of examples using JSON, so not sure if other formats work too.
Also, is it correct that the fetch function is not recognized?
Thanks for your replies. I’ve done the deserialisation manually by splitting rows etc, so that’s fine. Just don’t have experience with the request API.
This is what I do with fetch
async function getHosp() {
const response = await fetch('COVID19BE.csv');
const data = await response.text();
...
I tried something similar with Request but that didn’t work.
Also the CSV is about 3000 lines long so that might be a bit much for a widget?
It might help if you’d post what you did “similar”. Where’s the file stored on your device, how does your URL look etc.
Also: Why don’t you try to use Filemanager to load your file? If it’s just a static file, why the need to use fetch or request?
If anyone could point me in the right direction as in how to get the text data for this CSV with Request, instead of what I do with Fetch, that would be great.
Unfortunately, you didn’t post you script. It would be a lot easier to understand what you’re doing if you had.
De toute façon, cela fonctionne içi:
async function getCSV() {
let rawFeed = await loadText("https://belgium-covid-cases.netlify.app/COVID19BE_HOSP_11_dec-2020.csv");
console.log(rawFeed);
return rawFeed.split('\n');
}
async function loadText(url) {
let req = new Request(url)
let txt = await req.loadString()
return txt;
}
If you call getCSV, it will return the an array consisting of the CSV lines. You should be able to work from there.