Created
August 21, 2022 08:59
-
-
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)
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
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