Skip to content

Instantly share code, notes, and snippets.

@sertdfyguhi
Created December 13, 2020 07:46
Show Gist options
  • Select an option

  • Save sertdfyguhi/6a07e43ba200ea21c63213277d5ae31d to your computer and use it in GitHub Desktop.

Select an option

Save sertdfyguhi/6a07e43ba200ea21c63213277d5ae31d to your computer and use it in GitHub Desktop.
News scriptable widget
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-brown; icon-glyph: newspaper;
// Get a apiKey from newsapi.org and paste it in to apiKey variable
// You can also change the country by changing the country variable
let widget = new ListWidget()
let apiKey = "INSERT APIKEY HERE"
let country = "INSERT COUNTRY HERE"
let url = "http://newsapi.org/v2/top-headlines?country=" + country + "&apiKey=" + apiKey
let req = new Request(url)
let res = await req.loadJSON()
let news1 = res.articles[0]
let news2 = res.articles[1]
widget.addText("News").leftAlignText()
widget.addSpacer(5)
let n1t = widget.addText(news1.title)
n1t.leftAlignText()
n1t.font = Font.mediumSystemFont(12)
let n1rm = widget.addText("Read more")
n1rm.leftAlignText()
n1rm.font = Font.mediumSystemFont(10)
n1rm.url = news1.url
n1rm.textColor = Color.blue()
widget.addSpacer(7)
let n2t = widget.addText(news2.title)
n2t.leftAlignText()
n2t.font = Font.mediumSystemFont(12)
let n2rm = widget.addText("Read more")
n2rm.leftAlignText()
n2rm.font = Font.mediumSystemFont(10)
n2rm.url = news2.url
n2rm.textColor = Color.blue()
let gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [new Color("000c1c"), new Color("002454")]
widget.backgroundGradient = gradient
widget.presentMedium()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment