Created
October 3, 2020 07:02
-
-
Save sharn25/3f62e1969d7eaec22bd6b5f923651a0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: light-gray; icon-glyph: magic; | |
// Create your ID on openweathermap.org | |
// Get your api from there and set that in API_WEATHER | |
// Add your API KEY and the run the scritp in the scriptable app | |
// The City ID for your current location will appear in the log section of the app. | |
//API_KEY | |
let API_WEATHER = "YOUR_API_KEY";//Load Your api here | |
Location.setAccuracyToBest(); | |
let curLocation = await Location.current(); | |
console.log(curLocation.latitude); | |
console.log(curLocation.longitude); | |
let url = "http://api.openweathermap.org/data/2.5/weather?lat=" + curLocation.latitude + "&lon=" + curLocation.longitude + "&appid=" + API_WEATHER + "&units=metric"; | |
const data = await fetchWeatherData(url); | |
console.log("City Name: " + data.name); | |
console.log("City ID: " + data.id); | |
//get Json weather | |
async function fetchWeatherData(url) { | |
const request = new Request(url); | |
const res = await request.loadJSON(); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: light-gray; icon-glyph: magic;
// Create your ID on openweathermap.org
// Get your api from there and set that in API_WEATHER
// Add your API KEY and the run the scritp in the scriptable app
// The City ID for your current location will appear in the log section of the app.
//API_KEY
let API_WEATHER = "YOUR_API_KEY";//Load Your api here
Location.setAccuracyToBest();
let curLocation = await Location.current();
console.log(curLocation.latitude);
console.log(curLocation.longitude);
let url = "http://api.openweathermap.org/data/2.5/weather?lat=" + curLocation.latitude + "&lon=" + curLocation.longitude + "&appid=" + API_WEATHER + "&units=metric";
const data = await fetchWeatherData(url);
console.log("City Name: " + data.name);
console.log("City ID: " + data.id);
//get Json weather
async function fetchWeatherData(url) {
const request = new Request(url);
const res = await request.loadJSON();
return res;
}