Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Monalisa Sahu
Weather Portlet
February 28, 2012 4:39 AM
Answer

Monalisa Sahu

Rank: New Member

Posts: 2

Join Date: February 28, 2012

Recent Posts

Can anybody send me weather portlet
David H Nebinger
RE: Weather Portlet
February 28, 2012 5:08 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6520

Join Date: September 1, 2006

Recent Posts

Whatever you guys are working on, you should share notes.

Review all of the other recent posts on the weather portlet: where to get it, how to deploy it, how to configure it, and why invalid params result in blank screen.
Monalisa Sahu
RE: Weather Portlet
February 28, 2012 5:40 AM
Answer

Monalisa Sahu

Rank: New Member

Posts: 2

Join Date: February 28, 2012

Recent Posts

where should i put the war file of weather portlet in order to deploy it
David H Nebinger
RE: Weather Portlet
February 28, 2012 5:44 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6520

Join Date: September 1, 2006

Recent Posts

Again, this has all been covered in recent weeks as your friends have been doing the same things.

Search the forum to find the info.
Dave Weitzel
RE: Weather Portlet
December 6, 2012 1:02 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 169

Join Date: November 18, 2009

Recent Posts

Google has now stopped providing the weather api used in the portlet so it is not usable until updated to a new API
Hitoshi Ozawa
RE: Weather Portlet
December 6, 2012 2:17 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

It's already been fixed.

http://issues.liferay.com/browse/LPS-29542
Jitendra Rajput
RE: Weather Portlet
December 6, 2012 9:45 PM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 649

Join Date: January 7, 2011

Recent Posts

If you want to check code then look into WeatherWebCacheItem.java .
Old code with google API was like this

 1
 2public Object convert(String key) throws WebCacheException {
 3        Weather weather = null;
 4
 5        try {
 6            String text = HtmlUtil.stripComments(HttpUtil.URLtoString(
 7                "https://www.google.com/ig/api?weather=" +
 8                    HttpUtil.encodeURL(_zip)));
 9
10            int x = text.indexOf("temp_f data");
11
12            x = text.indexOf("\"", x) + 1;
13
14            int y = text.indexOf("\"", x);
15
16            float temperature = GetterUtil.getFloat(text.substring(x, y));
17
18            x = text.indexOf("/images", x);
19            y = text.indexOf("\"", x);
20
21            String iconURL = "https://www.google.com" + text.substring(x, y);
22
23            weather = new Weather(_zip, iconURL, temperature);
24        }
25        catch (Exception e) {
26            throw new WebCacheException(_zip);
27        }
28
29        return weather;
30    }


And new code with API change

 1
 2 public Object convert(String key) throws WebCacheException {
 3        Weather weather = null;
 4
 5        try {
 6            StringBundler sb = new StringBundler(5);
 7
 8            sb.append("http://free.worldweatheronline.com/feed/weather.ashx?key=");
 9            sb.append(WeatherPropsUtil.get("world.weather.online.api.key"));
10            sb.append("&q=");
11            sb.append(HttpUtil.encodeURL(zipName));
12            sb.append("&format=xml");
13            
14            String xml = HtmlUtil.stripComments(HttpUtil.URLtoString(sb.toString()));
15
16            Document document = SAXReaderUtil.read(xml);
17
18            Element rootElement = document.getRootElement();
19
20            Element currentConditionElement = rootElement.element(
21                "current_condition");
22
23            Element temperatureElement = currentConditionElement.element("temp_F");
24
25            float temperature = GetterUtil.getFloat(temperatureElement.getData());
26
27            Element iconElement = currentConditionElement.element("weatherIconUrl");
28
29            String iconURL = iconElement.getText();
30
31            weather = new Weather(zipName, iconURL, temperature);
32        }
33        catch (Exception e) {
34            throw new WebCacheException(zipName);
35        }
36
37        return weather;
38    }