Fetching weather data using java and the wunderground api

Ammar

I'm trying to fetch some weather data using java. I am using the following java api for fetching the data from wunderground.com

https://code.google.com/p/wunderground-core/

The example code they give on their website works okay for (Dortmund in Germany). However when I change the key from dortmund to Boston in the U.S.A, I get null pointer errors. Any idea what I could be doing wrong? Please try it and leave comments/advice. Thanks!

Code:

import de.mbenning.weather.wunderground.api.domain.DataSet;
import de.mbenning.weather.wunderground.api.domain.WeatherStation;
import de.mbenning.weather.wunderground.api.domain.WeatherStations;
import de.mbenning.weather.wunderground.impl.services.HttpDataReaderService;


public class weather {

    public static void main(String[] args)
    {

    // create a instance of a wunderground data reader
    HttpDataReaderService dataReader = new HttpDataReaderService();

    // select a wunderground weather station (ID "INORDRHE72" = Dortmund-Mengede)
    WeatherStation weatherStation = WeatherStations.ALL.get("INORDRHE72");
    // KMABOSTO22 is the ID for Boston South end
    //WeatherStation weatherStation = WeatherStations.ALL.get("KMABOSTO32");

    // set selected weather station to data reader
    dataReader.setWeatherStation(weatherStation);

    // get current (last) weather data set from selected station
    DataSet current = dataReader.getCurrentData();

    // print selected weather station ID
    System.out.println(weatherStation.getStationId());

    // print city, state and country of weather station
    System.out.println(weatherStation.getCity() + " " + weatherStation.getState() + " " + weatherStation.getCountry());

    //`enter code here` print datetime of measure and temperature ...
    System.out.println(current.getDateTime() + " " + current.getTemperature());
    }

}
rawdog

Check out the source code of the Wunderground API.

svn checkout http://wunderground-core.googlecode.com/svn/trunk/ wunderground-core-read-only

In the package de.mbenning.weather.wunderground.api.domain there is a class called WeatherStations. There you will find the content of all weather stations you can call in your code. Right now there are only a few ones:

public static final Map<String, WeatherStation> ALL = new HashMap<String, WeatherStation>();
static {
    ALL.put("INRWKLEV2", INRWKLEV2_KLEVE);
    ALL.put("INORDRHE110", INORDRHE110_GOCH);
    ALL.put("IDRENTHE48", IDRENTHE48_COEVORDEN);
    ALL.put("IZEELAND13", IZEELAND13_GOES);
    ALL.put("INORDRHE72", INORDRHE72_DORTMUND);
    ALL.put("INOORDBR35", INOORDBR35_BOXMEER);
}; 

All others won't work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python to get single day weather forecast from wunderground json api

From Dev

Using devbridge autocomplete and wunderground autocomplete API

From Java

Fetching data from Api in Reactjs using Axios

From Dev

Fetching data from facebook using graph api

From Dev

Issue with fetching data from excel (Using Java)

From Dev

Using yahoo weather Api

From Dev

Return Yahoo! weather API data in Celsius, using YQL

From Dev

Can't get weather data from API using angular components

From Dev

Fetching api data in angular

From Dev

Access A Value in Wunderground API

From Dev

rendering data with JSON (weather API)

From Dev

Fetching data from java api call from Pentaho Kettle Job

From Dev

Demand forecast using weather data

From Dev

Selenium Webdriver - Fetching column from a data table using Java 8

From Dev

OpenWeatherMap API vs Wunderground API?

From Dev

Fetching complex data using FMDB

From Dev

Fetching data using where clause

From Dev

Fetching data using NHibernate with Automapper

From Dev

Open Weather API use JSON data

From Dev

How do I get data from the wunderground API and display it on the screen in Android?

From Dev

How do I get data from the wunderground API and display it on the screen in Android?

From Dev

show local weather using openweathermap api

From Dev

show local weather using openweathermap api

From Dev

Can't display weather data using retrofit

From Dev

Using pandas to scrape weather data from wundergound

From Dev

Using For Loop with Weather Java Web Service

From Dev

How to check weather client is using PoolingHttpClientConnectionManager in java

From Dev

Using java.net.URLConnection to fetch data in html fetching only html code and not the actual data

From Dev

Fetching data from API that requires If-modified-since, using request.js in node,js

Related Related

  1. 1

    Python to get single day weather forecast from wunderground json api

  2. 2

    Using devbridge autocomplete and wunderground autocomplete API

  3. 3

    Fetching data from Api in Reactjs using Axios

  4. 4

    Fetching data from facebook using graph api

  5. 5

    Issue with fetching data from excel (Using Java)

  6. 6

    Using yahoo weather Api

  7. 7

    Return Yahoo! weather API data in Celsius, using YQL

  8. 8

    Can't get weather data from API using angular components

  9. 9

    Fetching api data in angular

  10. 10

    Access A Value in Wunderground API

  11. 11

    rendering data with JSON (weather API)

  12. 12

    Fetching data from java api call from Pentaho Kettle Job

  13. 13

    Demand forecast using weather data

  14. 14

    Selenium Webdriver - Fetching column from a data table using Java 8

  15. 15

    OpenWeatherMap API vs Wunderground API?

  16. 16

    Fetching complex data using FMDB

  17. 17

    Fetching data using where clause

  18. 18

    Fetching data using NHibernate with Automapper

  19. 19

    Open Weather API use JSON data

  20. 20

    How do I get data from the wunderground API and display it on the screen in Android?

  21. 21

    How do I get data from the wunderground API and display it on the screen in Android?

  22. 22

    show local weather using openweathermap api

  23. 23

    show local weather using openweathermap api

  24. 24

    Can't display weather data using retrofit

  25. 25

    Using pandas to scrape weather data from wundergound

  26. 26

    Using For Loop with Weather Java Web Service

  27. 27

    How to check weather client is using PoolingHttpClientConnectionManager in java

  28. 28

    Using java.net.URLConnection to fetch data in html fetching only html code and not the actual data

  29. 29

    Fetching data from API that requires If-modified-since, using request.js in node,js

HotTag

Archive