Search code examples
javamavenopenweathermap

Getting weather in OWM-JAPI


I'm writing Weather App on Java with OWM-JAPI (https://github.com/iamashks/OWM-JAPIs). Trying to get weather (like sunny, cloudy, etc) but I've got some issues.

getCity().getWeatherList()

Shows [Weather(conditionId=801, mainInfo=Clouds, moreInfo=небольшая облачность, iconCode=02d)]

I need to get info in moreInfo.

How can I do this? Thanks.

P.S. I can send you all my project on github, if you want it.

Here's my code:

import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.model.CurrentWeather;

public class Main {

    // configure owm: api key, lang, accuracy, etc
    private static OWM config(){
        OWM owm;
        owm = new OWM("061c88a24ac0ad18ae22534accea424a");
        owm.setUnit(OWM.Unit.METRIC);
        owm.setLanguage(OWM.Language.RUSSIAN);
        owm.setAccuracy(OWM.Accuracy.ACCURATE);
        return owm;
    }

    // getting city class
    private static CurrentWeather getCity() throws APIException {
        CurrentWeather cwd;
        cwd = config().currentWeatherByCityName("Stupino");
        return cwd;
    }

    // getting temperature
    private static int getTemperature() throws APIException, NullPointerException{
        int temp;
        temp = (int)Math.round(getCity().getMainData().getTemp());
        return temp;
    }

    // getting weather time
    private static String getTime() throws APIException {
        String time;
        int hours, minutes, seconds;
        hours = getCity().getDateTime().getHours();
        minutes = getCity().getDateTime().getMinutes();
        seconds = getCity().getDateTime().getSeconds();
        time = hours + ":" + minutes + ":" + seconds + ".";
        return time;
    }

    // sending weather info to user
    private static void message() throws APIException {
        String msgTime, msgCity, msgTemp, msgWeather;
        msgTime = "Погода на " + getTime();
        msgCity = "Город: " + getCity().getCityName();
        msgTemp = "Температура: " + getTemperature() + "°C.";
        System.out.println(msgTime + "\n" +
                msgCity + "\n" +
                msgTemp);

    }

    public static void main(String[] args) throws APIException, NullPointerException{

        message();

    }

}

Solution

  • Call getMoreInfo on the first elment of the list:

    getCity().getWeatherList().get(0).getMoreInfo()