2

I know this type of questions are asked before...but i cant figure it out...i have read this OS questions link1 and link2

Well i am developing a weather forecast app and for that i am using yahoo weather api.

I am using this url for response

 String url = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid="+woeid+
                " and u='c'&format=xml&env=store://datatables.org/alltableswithkeys";

        url = url.replace(" ","%20");

and i am getting this response

<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
    yahoo:count="1" yahoo:created="2016-03-25T12:45:44Z" yahoo:lang="en-US">
    <results>
        <channel>
            <yweather:units
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                distance="mi" pressure="in" speed="mph" temperature="F"/>
            <title>Yahoo! Weather - Ahmedabad, GJ, IN</title>
            <link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2295402/</link>
            <description>Yahoo! Weather for Ahmedabad, GJ, IN</description>
            <language>en-us</language>
            <lastBuildDate>Fri, 25 Mar 2016 06:16 PM IST</lastBuildDate>
            <ttl>60</ttl>
            <yweather:location
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                city="Ahmedabad" country="India" region=" GJ"/>
            <yweather:wind
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                chill="99" direction="315" speed="11"/>
            <yweather:atmosphere
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                humidity="20" pressure="1003.0" rising="0" visibility="16.1"/>
            <yweather:astronomy
                xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                sunrise="6:38 am" sunset="6:53 pm"/>
            <image>
                <title>Yahoo! Weather</title>
                <width>142</width>
                <height>18</height>
                <link>http://weather.yahoo.com</link>
                <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
            </image>
            <item>
                <title>Conditions for Ahmedabad, GJ, IN at 05:30 PM IST</title>
                <geo:lat xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">23.030809</geo:lat>
                <geo:long xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">72.591751</geo:long>
                <link>http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2295402/</link>
                <pubDate>Fri, 25 Mar 2016 05:30 PM IST</pubDate>
                <yweather:condition
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="30" date="Fri, 25 Mar 2016 05:30 PM IST"
                    temp="98" text="Partly Cloudy"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="28" date="25 Mar 2016" day="Fri" high="98"
                    low="74" text="Mostly Cloudy"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="30" date="26 Mar 2016" day="Sat" high="101"
                    low="77" text="Partly Cloudy"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="32" date="27 Mar 2016" day="Sun" high="100"
                    low="76" text="Sunny"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="30" date="28 Mar 2016" day="Mon" high="101"
                    low="71" text="Partly Cloudy"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="34" date="29 Mar 2016" day="Tue" high="103"
                    low="71" text="Mostly Sunny"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="32" date="30 Mar 2016" day="Wed" high="102"
                    low="73" text="Sunny"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="32" date="31 Mar 2016" day="Thu" high="99"
                    low="75" text="Sunny"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="34" date="01 Apr 2016" day="Fri" high="97"
                    low="73" text="Mostly Sunny"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="26" date="02 Apr 2016" day="Sat" high="99"
                    low="76" text="Cloudy"/>
                <yweather:forecast
                    xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
                    code="26" date="03 Apr 2016" day="Sun" high="101"
                    low="80" text="Cloudy"/>
                <description>&lt;![CDATA[&lt;img src="http://l.yimg.com/a/i/us/we/52/30.gif"/&gt;
&lt;BR /&gt;
&lt;b&gt;Current Conditions:&lt;/b&gt;
&lt;BR /&gt;Partly Cloudy
&lt;BR /&gt;
&lt;BR /&gt;
&lt;b&gt;Forecast:&lt;/b&gt;
&lt;BR /&gt; Fri - Mostly Cloudy. High: 98Low: 74
&lt;BR /&gt; Sat - Partly Cloudy. High: 101Low: 77
&lt;BR /&gt; Sun - Sunny. High: 100Low: 76
&lt;BR /&gt; Mon - Partly Cloudy. High: 101Low: 71
&lt;BR /&gt; Tue - Mostly Sunny. High: 103Low: 71
&lt;BR /&gt;
&lt;BR /&gt;
&lt;a href="http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2295402/"&gt;Full Forecast at Yahoo! Weather&lt;/a&gt;
&lt;BR /&gt;
&lt;BR /&gt;
(provided by &lt;a href="http://www.weather.com" &gt;The Weather Channel&lt;/a&gt;)
&lt;BR /&gt;
]]&gt;</description>
                <guid isPermaLink="false"/>
            </item>
        </channel>
    </results>
</query>

as in response...i am not getting temp in Celsius...plese help me

Community
  • 1
  • 1
H Raval
  • 1,903
  • 17
  • 39
  • just replacing spaces with "%20" might not be enough: do a proper `UrlEncode` – Cee McSharpface Mar 25 '16 at 12:52
  • i have tried that also...but no luck – H Raval Mar 25 '16 at 12:56
  • 1
    difficult to reproduce, the call returns a http response 400 most of the time: on https://developer.yahoo.com/weather they say that the public endpoint you're using, https://query.yahooapis.com/v1/public, has been deprecated as of March 15th, 2016 and they now enforce OAuth on a different address. – Cee McSharpface Mar 25 '16 at 16:40
  • 1
    the API does not work as documented, at least not for the location Ahmedabad (WOEID 2295402). The `u='c'` condition is used correctly, but results are always in Fahrenheit. I could also confirm that when testing OP's query in the YQL developer console [here](https://developer.yahoo.com/yql/console/?q=select%20*%20from%20weather.forecast%20where%20woeid%3D2295402%20and%20u%3D'c'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys), same with the code from the accepted answer of [this](http://stackoverflow.com/questions/21092164/yahoo-weather-api-celsius?lq=1) – Cee McSharpface Mar 25 '16 at 21:12
  • Also had the same problems a few days ago, but now it shows celsius correctly. It's also a bit unstable, so I think @dlatikay is onto something, and that it may be related to the enforcement of OAuth. – janlindso Mar 26 '16 at 03:40

2 Answers2

1

EDIT

I was trying your location on the console and you get Celsius in the forecast and current conditions if you request those items. I tried:

select item.forecast from weather.forecast where woeid = 2295402 and u='c'

that returned a 10-day forecast in Celsius. The URL would be

https://query.yahooapis.com/v1/public/yql?q=select%20item.forecast%20from%20weather.forecast%20where%20woeid%20%3D%202295402%20and%20u%3D'c'&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

Changing item.forecast to item.conditions does the same with the current conditions. I tried again select * and it gives the Fahrenheit error. Perhaps using separate queries for those items could help you?

Aris
  • 157
  • 1
  • 10
0

It seems the return temperature is in Fahrenheit.

You can convert this to Celsius using the following formula:

C = (F-32) x 5/9

ttdijkstra
  • 618
  • 4
  • 14