小人さんのメモ

オンラインノートとして利用しています。

Google BardでGASを書く

For example

 

Download weather data with GAS.

Sure, I can help you with that. Here are the steps on how to download weather data with GAS:

Open Google Apps Script.
Create a new project.
In the Script Editor, paste the following code:
Code snippet
function getWeatherData(location) {
  var url = "https://api.openweathermap.org/data/2.5/weather?q=" + location + "&appid=YOUR_API_KEY";
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url);
  xhr.onload = function() {
    if (xhr.status == 200) {
      var weatherData = JSON.parse(xhr.responseText);
      return weatherData;
    } else {
      console.log("Error getting weather data: " + xhr.status);
    }
  };
  xhr.send();
}
Use code with caution. Learn more
Replace YOUR_API_KEY with your OpenWeatherMap API key.

Save the script.
In the Script Editor, click the Run button.
In the dialog box that appears, enter the location for which you want to download weather data.
Click the Run button.
The weather data for the specified location will be downloaded and displayed in the Script Editor.
You can also use the getWeatherData function to download weather data for multiple locations. For example, the following code will download weather data for London, Paris, and Berlin:

Code snippet
function getWeatherDataForMultipleLocations() {
  var locations = ["London", "Paris", "Berlin"];
  var weatherData = [];
  for (var i = 0; i < locations.length; i++) {
    weatherData.push(getWeatherData(locations[i]));
  }
  return weatherData;
}
Use code with caution. Learn more