Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Last active April 20, 2021 19:10
Show Gist options
  • Select an option

  • Save woodwardtw/4f5300309749dcf8455e38eb2f9066c4 to your computer and use it in GitHub Desktop.

Select an option

Save woodwardtw/4f5300309749dcf8455e38eb2f9066c4 to your computer and use it in GitHub Desktop.
Example function in Google Script using https://openweathermap.org/current API
function otherWeather(){
const ss = SpreadsheetApp.getActiveSpreadsheet();//gets your spreadsheet
const sheet = ss.getSheetByName('APIData');//gets the sheet in your spreadsheet with this name
const apiUrl = 'http://api.openweathermap.org/data/2.5/weather?zip=05753,us&appid=YOUR_API_KEY&units=imperial';//goes to the API
const response = UrlFetchApp.fetch(apiUrl);//gets the API data
const json = JSON.parse(response.getContentText());//treat it as json
const data = [json.dt,json.weather[0].main, json.main.temp, json.wind.speed];//get the data we want from the API
sheet.appendRow(data);//write it to the sheet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment