Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created March 2, 2013 22:43
Show Gist options
  • Save knowtheory/5073597 to your computer and use it in GitHub Desktop.
Save knowtheory/5073597 to your computer and use it in GitHub Desktop.
// Fetch and append the current temperature
function fetchAndAppendWeather() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
// All the actual work is done in the top row.
// We get the link stored in cell A1
var weatherLink = sheet.getRange("A1").getValue();
// we set a formula importing a targeted portion of the web page
// specified by the link we stored in cell A1
var temperature = sheet.getRange("C1").setFormula("importxml(\""+weatherLink+"\",\"//div[@id='tempActual']\")");
// after we have fetched the current temperature
// insert a new row, where we'll store our new entry
sheet.insertRowAfter(1);
// stick the current time and the value of the temperature
// we've extracted into our newly created row.
sheet.getRange("B2").setValue(new Date());
sheet.getRange("C2").setValue(temperature.getValue());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment