![](/uploads/1/2/5/7/125799002/937968380.png)
31 Jan 2016CPOL
The free Yahoo Finance API has long been a reliable data source for many investors. Back in May 2017th, Yahoo decided to shut down the Yahoo Finance API finally. And even before this step, the Yahoo Finance API was changed frequently. I used it for a long time to export huge amount of historical data for stocks.
Brief introduction about YQL (Yahoo Query Language). Also describes how to use the REST API provided by Yahoo! to gather information.
Introduction
This tip aims at getting numerous amount of data using Yahoo! APIs using C#. Yahoo! APIs provide various information like weather, geographical information like country, city, ocean details, local US complete city information etc.
What is API?
API is Application Programming Interface. APIs can either be Desktop or Web APIs. Desktop APIs are usually DLL file which have functions defined in them. Microsoft itself provides numerous APIs in various DLLs like user32.dll, advapi32.dll, etc. Numerous functions are defined in them. Similarly, Web APIs are requests triggered by a client usually with a secret key for authentication. The response is usually a JSON or XML which needs to be parsed as required for our requirement.
Who Provides APIs?
Companies like Google, Yahoo!, Starbucks, Netflix and multiple others provide lot of APIs which can be utilized to get necessary information. Mostly APIs are required to sign up and secret keys are to be included in the request so that the server-side can understand it's a legitimate request.
What is YQL?
YQL is Yahoo! Query Language. It's similar to SQL and is designed to retrieve and manipulate data from APIs through a single Web interface.
https://developer.yahoo.com/yql/console/ is the YQL console which has complete details on tables, sample queries. Results of the query are either retrieved in JSON or XML as chosen. This utilizes Yahoo! APIs eliminating the need to write complex API programming. No need of any secret keys as well.
Yahoo! also provides the corresponding REST query so that Webclient can utilize the URL and formulate the JSON/XML response as needed.
What Information Does YQL Contain?
Weather, World geography, local US yellow pages, Google and its associated websites like news, search, Microsoft Bing, etc. Currently YQL holds 1064 tables.
Parse XML Output
Next comes the big work of parsing the XML from the REST API response. API response XMLs are complex, and can't easily be converted as such.
Normally, parsing XML is done by
XMLSerialize.Deserialize()
function. In order to store the deserialized object, we need to write class files which correspond properly stores node values for XML.But writing C# wrapper classes for large XML with numerous nodes is a tedious task. They sometimes end up in wrong class / variable assignment as well. But Visual Studio provides very easy way to accomplish this task.
C# Wrapper Classes for XML Deserialization
- Save a sample output from APIs to a XML file
- Open the XML in Visual Studio (2008, 2010, 2013, 2015)
- Once done, you will see a XML menu in the menu bar
- Click it and hit 'Create Schema'
- Once you hit it, XSD files will be created.
- Based on the XML schemas, single to 'N' number of XSD files can be created.
- Save all XSDs to a location say D:Temp
- Once done, the next step is to generate class files as needed
- Open Visual Studio command prompt from Start Menu
- As per below screenshot, please generate class file:
- xsd.exe is a XML schemas / Datatype support utility which is used to generate XSD, Class files
- /c - denotes generate class file || /l - denotes language CS, VB || /n - denotes Namespace || List of XSD files separated by spaces
- So wrapper class is generated for any complex XML file.
How to Code in C#?
Once you generate the class file, the top most class which holds every other classes is 'query'. Itès the base node in XML as well.
Code has detailed comments which will help to understand the flow detail. Below is sample output parsed from REST API XML.
History
- 31-Jan-2016: First revision
Conclusion
Any further comments to improve the tip are welcome.
References
- https://en.wikipedia.org/wiki/Web_API - Web API
- https://developer.yahoo.com/yql/guide/ - YQL Guide
- https://developer.yahoo.com/yql/console/ - YQL console to write and test queries
- https://msdn.microsoft.com/en-in/library/he66c7f1(v=vs.110).aspx - MSDN Deserializer
- https://satishlalam.wordpress.com/2009/06/05/auto-generating-c-wrapper-for-parsing-xml-files/ - Create class from XML file
- http://blogs.msdn.com/b/mapo/archive/2008/02/20/xsd-exe-error-generating-classes-for-schema-myschema-xsd-the-element-http-schemas-domainname-com-types-mytype-is-missing.aspx - Combine XSD to generate class file
This app is only available on the App Store for iOS devices.
What’s New
Ratings and Reviews
10.5K Ratings
![Yahoo weather api alternative free Yahoo weather api alternative free](/uploads/1/2/5/7/125799002/526795992.jpg)
An elegant blend of striking photography and nuanced information, Yahoo’s interactive weather app will delight you every time you open it. Expanding the wonderfully streamlined interface reveals a 10-day forecast, heat and wind maps, and other handy displays, while a quick swipe lets you instantly check the temperature in another favorite location.
Nicely laid out
I've tried several weather apps, and there are some nice features that make this one my overall favorite so far. First of, design-wise, I really like the background photos selected from Flickr. Much nicer than seeing the san he background all the time. The main design feature I like its that all the info, hourly forecast, daily forecast, etc, are all in one screen. You just have to scroll to u find what you need, unlike some of the other apps I've tried, where you have to tap around and open different screens to see different info, of course navigating around introduce ads. As for accuracy, we haven't had much actual weather since I've been using the app, but so far it's been pretty accurate.
Detailed and accurate
I have not tried a whole lot of weather apps, but I did read about several before choosing one. The reason I tried this one is first, that it is free. Second, it is detailed with many options and as far as I can tell, seems very accurate.
I love all the little animations that it adds for effect. Like showing the windmills spinning according to how fast the wind is blowing, and showing the sun moving across until it hits the area that it currently is at in the sky. There is a map of the area at the bottom that has several options for viewing such a satellite and radar. You can add and delete cities and move them around as you like. It gives a 10 day forecast. And a beautiful picture to go with each city.
For a free app, this one is very impressive. And the advertisements that are inevitable with a free app, are non-intrusive. They show up as a section of their own as you scroll down through the various sections of each city. So you simply scroll past them and it is no big deal. They do not interfere with viewing.
I love all the little animations that it adds for effect. Like showing the windmills spinning according to how fast the wind is blowing, and showing the sun moving across until it hits the area that it currently is at in the sky. There is a map of the area at the bottom that has several options for viewing such a satellite and radar. You can add and delete cities and move them around as you like. It gives a 10 day forecast. And a beautiful picture to go with each city.
For a free app, this one is very impressive. And the advertisements that are inevitable with a free app, are non-intrusive. They show up as a section of their own as you scroll down through the various sections of each city. So you simply scroll past them and it is no big deal. They do not interfere with viewing.
An elegant blend of striking photography and nuanced information, Yahoo’s interactive weather app will delight you every time you open it. Expanding the wonderfully streamlined interface reveals a 10-day forecast, heat and wind maps, and other handy displays, while a quick swipe lets you instantly check the temperature in another favorite location.
Information
Requires iOS 11.0 or later. Compatible with iPhone, iPad, and iPod touch.
English, Arabic, Bengali, Bulgarian, Catalan, Croatian, Czech, Danish, Dutch, Estonian, Filipino, Finnish, French, German, Greek, Gujarati, Hebrew, Hindi, Hungarian, Indonesian, Irish, Italian, Japanese, Kannada, Korean, Latvian, Lithuanian, Malay, Malayalam, Marathi, Norwegian Bokmål, Polish, Portuguese, Romanian, Russian, Serbian, Simplified Chinese, Slovak, Slovenian, Spanish, Swedish, Tamil, Telugu, Thai, Traditional Chinese, Turkish, Ukrainian, Urdu, Vietnamese
Supports
Family Sharing
With Family Sharing set up, up to six family members can use this app.
![](/uploads/1/2/5/7/125799002/937968380.png)