Skip to content

Instantly share code, notes, and snippets.

@csteinlehner
Last active August 10, 2022 16:56
Show Gist options
  • Select an option

  • Save csteinlehner/6208ce202f6ffcdd710d32a47152f41f to your computer and use it in GitHub Desktop.

Select an option

Save csteinlehner/6208ce202f6ffcdd710d32a47152f41f to your computer and use it in GitHub Desktop.

Revisions

  1. csteinlehner revised this gist Aug 10, 2022. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions temp_c_f.js
    Original file line number Diff line number Diff line change
    @@ -41,8 +41,6 @@ tempC.font = Font.mediumRoundedSystemFont(detailFontSize)
    tempC.textColor = cColor;
    tempC.centerAlignText();

    widget.addSpacer()

    // Show temp in F
    let tempFVal = Math.round(tempValK * 1.8 - 459.67).toString() + "º F";
    let tempF = widget.addText(tempFVal);
  2. csteinlehner renamed this gist Aug 10, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. csteinlehner created this gist Aug 10, 2022.
    56 changes: 56 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    // Variables used by Scriptable.
    // These must be at the very top of the file. Do not edit.
    // icon-color: red; icon-glyph: magic;

    // OpenWeatherMap API 2.5 Key
    const apiKey = "__YOUR_API_KEY__";

    // Config sizes & colors
    let detailFontSize = 40
    let cColor = Color.white();
    let fColor = Color.orange();

    // Get current location
    Location.setAccuracyToKilometer();
    const loc = await Location.current();

    // Get Weather data
    async function getCurrentTemp() {
    let currentTemp = 0
    try {
    let weatherReq = "https://api.openweathermap.org/data/2.5/onecall?lat=" + loc.latitude + "&lon=" + loc.longitude + "&exclude=minutely,hourly,daily,alerts" + "&appid=" + apiKey
    let weatherData = await new Request(weatherReq).loadJSON();
    let currentTemp = weatherData.current.temp;
    return currentTemp;
    } catch (error) {
    }
    }

    // Fill widget
    let widget = new ListWidget();

    widget.backgroundColor = Color.black();

    // Get temp in Kelvin
    let tempValK = await getCurrentTemp();

    // Show temp in C
    let tempCVal = Math.round(tempValK - 273.15).toString() + "º C";
    let tempC = widget.addText(tempCVal);
    tempC.font = Font.mediumRoundedSystemFont(detailFontSize)
    tempC.textColor = cColor;
    tempC.centerAlignText();

    widget.addSpacer()

    // Show temp in F
    let tempFVal = Math.round(tempValK * 1.8 - 459.67).toString() + "º F";
    let tempF = widget.addText(tempFVal);
    tempF.font = Font.mediumRoundedSystemFont(detailFontSize)
    tempF.textColor = fColor;
    tempF.centerAlignText();

    // Close Widget
    Script.setWidget(widget);
    widget.presentSmall();
    Script.complete();