Widget Examples

I am so happy it helps.

1 Like

A hint: there is an API which gives you the real time prices of all Gas stations (in Germany) by location and type of fuel:

1 Like

Based on a widget I found here:(Covid incidence by location):

If you add the parameter

diesel@50.5525979, 9.7259095

The widget shows the current price. If no parameter is given, the current location is used and e5 is shown.

And I woul ask you to get your own api-Key at tankerkönig, it is free.

I am no JS pro and the script is not bullet proof and I do not know how to post a script properly. But it does what you want:


const apiURL = (location,fuel) =>
`https://creativecommons.tankerkoenig.de/json/list.php?lat=${location.latitude.toFixed(3)}&lng=${location.longitude.toFixed(3)}&rad=1&sort=price&type=${fuel}&apikey=c5e49ed8-d412-d598-7f86-e87609a12d6e`

console.log(apiURL)

let widget = await createWidget()
if (!config.runsInWidget) {
  await widget.presentSmall()
}
Script.setWidget(widget)
Script.complete()

async function createWidget(items) {
  let location
  if(args.widgetParameter) {
    
    arg1=args.widgetParameter.split("@")
    console.log(arg1)
    const fixedCoordinates =   arg1[1].split(",").map(parseFloat)
    location = {
      latitude: fixedCoordinates[0],
      longitude: fixedCoordinates[1]
    }
    fuel=arg1[0]
  } else {
    location = await Location.current()
    fuel="e5"
  }

  const data = await new Request(apiURL(location,'e5')).loadJSON()
  if(!data) {
    const errorList = new ListWidget()
    errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.")
    return errorList
  }
  console.log(data)
  const attr = data.stations[0]
  incidence=attr.price
  const list = new ListWidget()
  if(Device.isUsingDarkAppearance()){
    const gradient = new LinearGradient()
    gradient.locations = [0, 1]
    gradient.colors = [
      new Color("111111"),
      new Color("222222")
    ]
    list.backgroundGradient = gradient
  }
  const header = list.addText("⛽️"+" "+fuel.toUpperCase())
  header.font = Font.mediumSystemFont(13)
  list.addSpacer()
  const label = list.addText(incidence+"€")
  label.font = Font.boldSystemFont(24)
  list.addText(attr.street)
  return list
}

3 posts were split to a new topic: German Fuel Station Prices

Hi, could you help me?

Isn’t this an exact duplicate of the post in the following topic?

Have you read the information I posted there the other day about what that error message means and details of the documentation you need to look at?

Simply add:

let widget = await createWidget()

before the Format the Widget comment and may be at the end:

Script.setWidget(widget)
Script.complete()

I just saw it! Thanks again I guess!

Awesome widgets over here!

I made a widget, that shows you a live webcam photo from foto-webcam.eu:
https://gist.github.com/andreasRedeker/da8fdee258326af14400187c521723df

Hi everybody,
fresh clean air is very important to stay healthy. So I’ve created a widget to check the current Air pollution of your city.


You can check it out here:

3 Likes

Looking for this too!
@Nathan_Dickin I don’t think it does https://developer.apple.com/forums/thread/650869

Widgets in iOS 14 can’t update real time. They’re completely unsuitable for this kind of use case.

Now also location based widget available to check the current Air Quality in your city:
Bildschirmfoto 2020-11-22 um 19.49.14

1 Like

And the Dilbert one:


Also support Peanuts and Garfield. It uses multiple widgets combined in a smart stack to display one pic per widget. So it’s readable even in a small widget.


I created a Coptic Calendar Widget that downloads the information for today’s readings and Coptic month and day. Also a broken clock :sweat_smile:

When trying to customize this script I receive the following error:

2020-12-02 11:43:29: Error on line 21:31: Expected value of type string but got value of type undefined.

I have basically recreated your base and script. Have you seen this message?

I want to share mine. It does show some economic indexes we use in Chile (unidad de fomento, unidad tributaria mensual, and USD/CLP rate). It’s fugly, with chunks taken from a COVID-19 Scriptable widget I’ve found, but it works.

Here is the code:

const url = 'https://mindicador.cl/api'
const request = new Request(url)
const res = await request.loadJSON()
const table = new UITable()

function createWidget(pretitle, title, subtitle, color) {
  let w = new ListWidget()
  w.backgroundColor = new Color(color)
  let preTxt = w.addText(pretitle)
  preTxt.textColor = Color.white()
  preTxt.textOpacity = 0.8
  preTxt.font = Font.systemFont(16)
  w.addSpacer(5)
  let titleTxt = w.addText(title)
  titleTxt.textColor = Color.white()
  titleTxt.font = Font.systemFont(22)
  w.addSpacer(5)
  let subTxt = w.addText(subtitle)
  subTxt.textColor = Color.white()
  subTxt.textOpacity = 0.8
  subTxt.font = Font.systemFont(18)
  return w
}

let widget = createWidget("Indicadores", `UF ${res.uf.valor}\nUTM ${res.utm.valor}\nDolar ${res.dolar.valor}`, ``, "#7b68ee")
Script.setWidget(widget)
Script.complete()
  

Hello,

finally I can scape data from Essen website.
I dont understand how you scrape the data to json in your git.
Can you explain it?

BR
gentlel

can you share the shortcut too please.

I get a 404 error on that GitHub page, do you need to make the gist publicly-accessible?