xxxxxxxxxx
83
//query String
var url = 'https://api.openweathermap.org/data/2.5/weather?q=';
// our search term
let city = 'London';
var units = '&units=imperial&';
// our api key plus units, input your own API key below, leave no spaces
var apiKey = 'appid='+'ENTER_YOUR_OWN_API_KEY';
//variable to eventually hold all our weather data
var weather;
var input;
let button;
let cities;
let loaded = false;
let cityText="";
function setup() {
cities = createSelect();
cities.option("London")
cities.option("Dublin")
cities.option("Anchorage");
cities.option("Quito");
cities.option("Moscow");
cities.option("Buffalo");
button = createButton('submit');
button.mousePressed(userWeather);
cities.changed(chooseCity);
createCanvas(600, 400);
}
function userWeather() {
let request = url + city + units + apiKey;
console.log(request);
loadJSON(request, gotData, function(er){
console.log(er)
});
}
function gotData(d) {
weather = d;
console.log(d);
if(d){
loaded =true;
}
}
function chooseCity() {
city = cities.value();
}
function draw() {
background(0);
fill(255);
// console.log(loaded);
if (loaded) {
let temp = weather.main.temp;
let sz =map( weather.main.temp,0,100,0,height-50);
cityText = weather.name;
ellipse(width / 2, height / 2, sz, sz);
text("It is " + temp + " degrees F in: " + cityText, 10, 30);
}
}
/// davids api key
// '0632e67f6c91b04250bb8d53d7c72fc0'