using System; using Microsoft.SPOT; using System.Net; using System.Text; using System.IO; namespace NPlus_Ethernet_Testing { public class WebRetrieve { public WebRetrieve() { } public string GetCurrentConditions(string zipcode) { Uri address = new Uri("http://xml.weather.yahoo.com/forecastrss?p=" + zipcode); // Create the web request HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); // Get response HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); string newLine = reader.ReadLine(); int lineNumber = 0; while (newLine != "") // While we still got data { if (lineNumber == 32) // The Current weather data seems to be on line 32 always. return newLine.Split('<')[0]; // The line also has a <BR/> at the end, get rid of that by spliting it and using the first part. newLine = reader.ReadLine(); // Read next line lineNumber++; // Update line number } return "Could Not Get Data"; // In case that we dont get to line # 32 for some odd reason } } }
Getting Weather Data for your zip-code.
Started by Omar (OZ), Nov 27 2010 07:26 PM
5 replies to this topic
#1
Posted 27 November 2010 - 07:26 PM
This is a little class I started making, right now it fetches the current weather data and in the future I will add code to get the forecast. I wanted to make it into a project that shows it on a 16x2 LCD, but I couldn't keep this fun little code from you guys! I hope you can find some use for it.
- Giuliano likes this
#2
Posted 27 November 2010 - 09:17 PM
I also have a massive class for this that uses AWOS's at local airports. You need an ICAO to make it work.
http://files.chrisseto.com/7KE
#3
Posted 27 November 2010 - 09:32 PM
I also have a massive class for this that uses AWOS's at local airports. You need an ICAO to make it work.
http://files.chrisseto.com/7KE
It looks amazing! Although I did't dive into it, its far too complicated for me. but nice job!
#4
Posted 28 November 2010 - 02:39 AM
Thanks for both of you for this... I was looking for a project to use on my Netduino Plus.
~ Eric D. Burdo ~ http://brick-labs.com/
Today LED's, tomorrow, the world!!! Well, OK, maybe servos.
Today LED's, tomorrow, the world!!! Well, OK, maybe servos.
#5
Posted 28 November 2010 - 02:45 AM
Could you let me know if my code works out for you?Thanks for both of you for this... I was looking for a project to use on my Netduino Plus.
#6
Posted 29 November 2010 - 02:35 PM
Ahh, feels good to be back (I was on vacation in England :} ). This could be very useful with my new project, I will need to be able to fetch data from an online source, and as of right now am not sure how too :/. The source being Twitter
Thanks a lot Omar!
-Cwbh
-Cwbh
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users