Skip to content

Instantly share code, notes, and snippets.

@0xVesion
Created August 21, 2022 08:59
Show Gist options
  • Save 0xVesion/ffa35789db403407b24a88f36e2a8cdb to your computer and use it in GitHub Desktop.
Save 0xVesion/ffa35789db403407b24a88f36e2a8cdb to your computer and use it in GitHub Desktop.
Scriptable.app script for google sheets widget (inspired by https://medium.com/@mutsuda/create-an-ios-widget-showing-google-spreadsheets-data-856767a9447e)
async function fetchSheetValues({id, name, apiKey}) {
const url = 'https://sheets.googleapis.com/v4/spreadsheets/' + id + '/values/' + name + '?alt=json&key=' + apiKey;
const json = await new Request(url).loadJSON()
console.log(`Head to this url to see the raw data: ${url}`);
return json.values
}
function buildWidget(data) {
const widget = new ListWidget()
widget.backgroundColor = new Color("#000080")
const text = widget.addText(data)
text.textColor = Color.white()
text.font = new Font("Avenir-Heavy", 20)
return widget
}
const values = await fetchSheetValues({
id: "abc123",
name: "Sheet 1",
apiKey: "XXXX",
})
const data = `Value: ${values[1][6]}`;
console.log(`This will be displayed: "${data}"`);
Script.setWidget(buildWidget(data))
Script.complete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment