Lab 13 Web Eng
Lab 13 Web Eng
Web Engineering
Submitted by:
weather data for a specified city. Use the https module to make the API call, and the querystring
+`lat=${latitude}&lon=${longitude}&appid=${API_KEY}`
if (error) {
else {
+ response.body.main.temp
);
+ response.body.main.temp_max
+ response.body.main.temp_min
);
console.log('Humidity today is '
+ response.body.main.humidity
);
})
// Function call
forecast(latitude, longitude);
b. Parse the JSON response from the API call and extract the relevant
weather data, such as temperature, humidity, and wind speed.
def get_weather_data(location):
# Set the parameters
params = {
'location': location,
'fields': 'temperature,humidity,wind_speed',
'units': 'metric',
'timesteps': '1h',
'apikey': api_key
}
# Make the API request
response = requests.get(url, params=params)
# Parse the response
weather_data = response.json()
temperature = weather_data['data']['timelines'][0]['intervals'][0]['values']['temperature']
humidity = weather_data['data']['timelines'][0]['intervals'][0]['values']['humidity']
wind_speed = weather_data['data']['timelines'][0]['intervals'][0]['values']['wind_speed']
# Return the weather data
return {'temperature': temperature, 'humidity': humidity, 'wind_speed': wind_speed}
function c1() {
console.log('an event occurred!');
}
function c2() {
console.log('yet another event occurred!');
}
4. In the processing module, create an event listener that receives the weather data and
performs additional calculations or formatting as needed. For example, you could convert the
temperature from Celsius to Fahrenheit, or display the weather data in a user-friendly
format.
function temperatureConverter(valNum) {
valNum = parseFloat(valNum);
document.getElementById("outputCelsius").innerHTML = (valNum-32) / 1.8;
}