Use the Weatherbit API to obtain a 5-day weather forecast with High and Low-temperature information. You will
Question:
Use the Weatherbit API to obtain a 5-day weather forecast with High and Low-temperature information. You will need to register to obtain an API Key to use the Weatherbit API. Keys are generally made available within a couple of minutes. Once having a key, you can check your daily usage quota with the following call: curl -s -g https://api.weatherbit.io/v2.0/subscription/usage?key=[YOUR-API-KEY]
sample output
weather for 2022-10-10 HI: 13.76c LOW: 5.4c
submit forecast .sh file
Sol106:
here is an example of how to use the Weatherbit API to obtain a 5-day weather forecast with high and low-temperature information using Python:
import requests
API_KEY = "YOUR_API_KEY"
city = "London"
response = requests.get(f"https://api.weatherbit.io/v2.0/forecast/daily?city={city}&key={API_KEY}")
if response.status_code == 200:
data = response.json()
for day in data["data"][:5]:
date = day["datetime"]
high_temp = day["high_temp"]
low_temp = day["low_temp"]
print(f"Weather for {date} - HI: {high_temp}C LOW: {low_temp}C")
else:
print("Error fetching weather data.")
Replace YOUR_API_KEY
with your own API key obtained from Weatherbit, and London
with the city you want to get the weather forecast for. This code will print the high and low temperature for the next 5 days.