Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save javebratt/3706ac159fec9520d14be3a335f24c51 to your computer and use it in GitHub Desktop.
Save javebratt/3706ac159fec9520d14be3a335f24c51 to your computer and use it in GitHub Desktop.
// Modified from @mutsuda's https://medium.com/@mutsuda/create-an-ios-widget-showing-google-spreadsheets-data-856767a9447e
// by @levelsio
// HOW TO
// 1) Make a Google Sheet, we'll pull the first cell e.g. A1
// 2) Publish your Google Sheet, File -> Publish To Web
// 3) Copy the SHEET_ID in the URL, put it in here below:
const endpoint = "https://spreadsheets.google.com/feeds/cells/SHEET_ID/1/public/full?alt=json"
// 4) Install Scriptable @ https://apps.apple.com/us/app/scriptable/id1405459188
// 5) Copy this entire script in to Scriptable (tip: you can send it to your iPhone via Whatsapp/Messenger/Telegram etc)
// Function that performs the request to the JSON endpoint
async function loadItems() {
let at = endpoint
let req = new Request(at)
let corpo = await req.loadJSON()
// We return just the cells
return corpo.feed.entry
}
// Request the spreadsheet data
let json = await loadItems()
// Obtaining the content of the exact cell we are looking for
stockValue = json[0].content["$t"]
// Create the widget
let w = new ListWidget()
// w.backgroundColor = new Color("#000080")
// Add the value of the stock to the widget
t = w.addText(stockValue)
t.textColor = Color.black()
t.font = new Font("Avenir-Heavy",24)
Script.setWidget(w)
Script.complete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment