Skip to content

Instantly share code, notes, and snippets.

@sharn25
Created October 3, 2020 07:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharn25/3f62e1969d7eaec22bd6b5f923651a0d to your computer and use it in GitHub Desktop.
Save sharn25/3f62e1969d7eaec22bd6b5f923651a0d to your computer and use it in GitHub Desktop.
// 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;
}
@artwlsdks
Copy link

// 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