Regarding the showing weather data using Weatherbit api

Can someone please share the code for how to get the weather description from the api

Hi @ansh_10 Our team is looking into this. You may expect a reply soon.

@ansh_10

Kindly refer to this python code:

import requests

url = "https://api.weatherbit.io/v2.0/current?lat=35.7796&lon=-78.6382&key=YOUR_KEY&include=minutely"

payload={}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Replace your API key in the placeholder.

Kindly follow this documentation for further details Weatherbit | Current Weather API Documentation

function show_temp()
{
    city = document.getElementById("city").value

    httpRequest = new XMLHttpRequest();
    url = "https://api.weatherbit.io/v2.0/current?city="+city+"&key=0fa8c8977a384bb7afe54310cfeee21d"
    httpRequest.open("GET", url)
    httpRequest.send();

    httpRequest.onreadystatechange = function(){
        if(this.readyState == 4 && this.status == 200)
        {
            user_data = JSON.parse(this.responseText);
            document.getElementById("temp").innerHTML = user_data.data[0].temp;
            document.getElementById("description").innerHTML = user_data.data[0].weather.description
            document.getElementById("humidity").innerHTML = user_data.data[0].rh;
            document.getElementById("wind").innerHTML = user_data.data[0].wind_spd;
            document.getElementById("obv_time").innerHTML = user_data.data[0].ob_time;
            document.getElementById("name").innerHTML = city
        }
    }
}
This is my code, can you tell me how to embed that snippet in this code?

Hi,

Your code seems correct. You don’t need to embed my python script into your JS code. You have done correctly.

Are you able to get weather description?

1 Like

Yaa, I am able to get the description now but before the description area always showed undefined.

1 Like