Getting Weather Information from Yahoo Web Services in C#

09.02.2010 0

I wrote an article sometime back on The CodeProject that dealt with Geolocation. I wrote this back in 2005 so I figured I would update my post here and add a new twist.

The new code still uses YAHOO’s web services, however this time I am writing it in LINQ and C#. So lets dive right in shall we? This is a simple console based program, you can re do it as a webapp or a forms program, but the concept is the same.
using System;
using System.Linq;
using System.Xml.Linq;

namespace YahooWeather
{
    class Program
    {
        public string appid { get; set; }

        public Program(string appid)
        {
            this.appid = appid;
        }
    }
}

It starts off as any program does with a basic namespace deceleration, as you can see there is one property called appid that gets set when you create an instence of this class.

        public string GetWoeid(string Zipcode)
        {
            string query = String.Format("http://where.yahooapis.com/v1/places.q('{0}')?appid={1}", Zipcode, this.appid);
            XDocument thisDoc = XDocument.Load(query);
            XNamespace ns = "http://where.yahooapis.com/v1/schema.rng";

            return (from i in thisDoc.Descendants(ns + "place") select i.Element(ns + "woeid").Value).First();
        }

This function loads up http://where.yahooapis.com/v1/ and grabs the XML stream with LINQ then returns the woeid. The woeid is a unique number that identifies your location

Next, we have to get the weather RSS feed from Yahoo using your woeid

        public void GetWeather(string Zipcode)
        {
            string query = String.Format("http://weather.yahooapis.com/forecastrss?w={0}", GetWoeid(Zipcode));
            XDocument thisDoc = XDocument.Load(query);
            XNamespace ns = "http://xml.weather.yahoo.com/ns/rss/1.0";
            var results = (from i in thisDoc.Descendants(ns + "forecast") select i);

            foreach (var thisResult in results)
                Console.WriteLine("{0}, it will be {1} with a low of {2} and a high of {3}", thisResult.Attribute("date").Value, thisResult.Attribute("text").Value, thisResult.Attribute("low").Value, thisResult.Attribute("high").Value);
        }

This function prints out the current weather conditions. In the same way we got the woeid (parsing xml/rss), we are getting the weather results. All thats left now is the main procedure.

        static void Main(string[] args)
        {
            Program thisYahoo = new Program("<strong>YOUR KEY HERE</strong>");

            Console.Write("Enter your zip code please: ");
            thisYahoo.GetWeather(Console.ReadLine());

            Console.Write("Press Enter...");
            Console.ReadLine();
        }

View the Yahoo GeoPlanet API documentation | View the Yahoo Weather API documentation | Get a Yahoo application ID

  Weather.zip (736 bytes, 5 hits)

Batch resizing of multiple images in multiple sizes

23.07.2009 1

Multiresize About

Introducing MultiResize
Great for web developers or anyone who needs to create multiple or single sizes of any image(s). Have a photo gallery and need to create multiple images in multiple sizes? Create as many sizes as you want, process as many images as you want and name them however you want.

Features
High quality bi-cubic resizing algorithm
Supports for any amount of files
Supports for any number or resizing jobs
Saving and loading of jobs for repetitive tasks
Image aspect ratio maintained

Requires Microsoft .Net v2

Usage
Step 1: Click on the “Add Images” to select the images you wish to process.
Step 2: Click on “Configure Jobs” to setup the resize jobs for each file.
Step 3: Click on “Process Images” to render the images

The resulting images are created in the same folder as the source images.

Screen shots

Multiresize Jobs

Multiresize Jobs

Multiresize Main

Multiresize Main

Nag Screen
One when you start the application, another when you start processing your file(s) and lastly when you finish processing your file(s).
You can process an unlimited number of images and preform an unlimited number of jobs with this demo.  When you register the nags go away.

Purchase for $10.00 | Video tutorial (from DownloadTube)

  MultiResize-Setup.msi (574.5 KB, 13 hits)

Awards:

Hosted On:

Gallery extension for BlogEngine

04.06.2009 0

Paul Tumelty wrote a very nice BlogEngine component that creates a page of Lightbox 2 links dynamically from a directory of images.

I have added to this extension, you can now pass in a “SetName” to define a set of images.  Defining a set of images in lightbox allows you to use the built in Previous and Next capabilities of Lightbox 2.

I also noticed an error with thumbnail generation, it was hard coded to a value of 75, that has been fixed as well.

Get the Lightbox JS here
Get the Gallery extension here

Download the update

  Blogengine-Lightbox.zip (3.4 KB, 10 hits)

I also had an issue with Prototype interfering with lightbox (making the application appear not to work).  If this happens to you simply update the blog.js file in your installation root directory of BlogEngine to correct this error.

Vista Sidebar Gadget

23.11.2007 0

There is an observatory close to where I live called the “Mount Washington Observatory” (http://www.mountwashington.org/). It just so happens to be located on top of Mount Washington who would have thought it? Anyway, they post pictures every 15 minutes from the five different public cameras located across on the property. I thought it would be cool to make them into a Vista slide show gadget, while adhering to bandwidth conservation. The images the gadget uses are pulled from a mirror site (I mirror them on this server, http://devclarity.com/MWO) so not to choke MWOs bandwidth. The images will cycle often (configurable) but will only be updated every 15 minutes, there is also a time each day where no new images will be processed (9pm to 3am, the cams have trouble seeing in the dark :-) ).

Updates
Nov 26 2007: Minor Bug Fixes
Dec 20 2008: Fixed image overflow

Credits
My friend Kirk for doing up the graphics and Mount Washington (of course) for posting the images in the first place.

Screen shot (It’s dusk so the image is dark, you can zoom in by clicking on the image)

Download Link

This gadget is defunt, the image mirror no longer exists.

  MtWashington.gadget (204.7 KB, 8 hits)

Backup Mover

13.11.2007 5

You want to set up a incremental backup in Acronis to safeguard your data.  You tell Acronis to preform the incremental backups all week long, but you also want to preform a full backup on the first of the week.  Thats where Backup Mover works it’s magic, Backup Mover will move your incremental backups to a time stamped sub-directory allowing Acronis to preform another full backup.

Simply configure Backup Mover with it’s configuration interface, and apply the generated settings to Acronis or whatever backup program you use.

Now your backups will be stored for 2 weeks and full backups will be preformed on Saturdays!

Backup Mover is free software but requires .NET V2 runtime and is available in both 32 and 64 bit flavors.

Updates 11/12/07:
Event Log Logging (For Servers)
Sometimes delete directory failed, added new recursive delete.

Updates 11/14/2007:
Installer has been fixed to only check for installations of .NET v2

  Backup_Mover_x64.zip (333.0 KB, 15 hits)

  Backup_Mover_x86.zip (333.1 KB, 22 hits)

Vista DHCP Patch

22.10.2007 0

I installed Vista the other day only to find out the DHCP Broadcast was taken out of the default settings for the network interface.  As a result Vista couldn't find my Linksys router, to say the least I was annoyed.  I searched around and found the KB for the issue and wrote a quick little program to alter the registry.  (The reason I made it a program is I will be patching a bunch of machines and wanted an easy way to apply the patch.  And seeing as how the network interface guids are not the same from machine to machine I needed to use a sprinkle of logic).

You will need to run the patch as Administrator to allow access to the registry. After applying then reboot your machine and your network problems will have vanished.

You can always alter it maually or use this little timesaver:

  VistaDHCPFix.zip (3.1 KB, 49 hits)

KB:
http://support.microsoft.com/kb/928233

Clipboard Text Scrubber

22.09.2007 0

When creating web pages for clients I am often asked to copy the exact verbage a client sends me in an Word Doc, PDF or yes even the worst, Powerpoint.  Copy and pasting the text from a fiormatted source can often cause issues and productivity slow downs, I often need to spend time stripping the formatting from the text that I copied.  Well enough is enough, I found this program a few months ago and use it all the time to strip the excess formatting from my copy and paste operations.  Just start it up, land forget about it (it runs silently in the background scrubbing your clipboard when ever it has new data on it).  I highly recommend this program.

Homepage: 

Download Link:
http://www.binaryfortress.com/Files/ClipboardTextScrubber/Clipboard_Text_Scrubber.exe

Clipboard Scrubber

Mad Clickr (Simon) in Adobe Air

21.09.2007 0

Adobe Air is a way to run web applications on your desktop while proving a means, for the web developer, to control the local system (Play sounds, write to files etc).  Anyway I wanted to give this new gadget a try, I have to say I wasn’t impressed with the technology.  I have been writing web applications for desktop use long before Adobe Air, and while Air does give you access to some areas of the system a web app would not normally have I didn’t find it to be an earth shattering development like Adobe would have you think.

Anyway, I wrote this Simon like game to give the technology a spin.  By no means is this a great game mind you (it even looks a little cheesy, like it belongs in the 70’s [doh]).  But without further adue here is Mad Clickr.  (If nothing more you can take it apart and look at the JS)

  MadClickr.air (811.3 KB, 7 hits)

Drive Monitor

21.09.2007 0

Ever want to monitor your server(s) or your capture box(s) drive space from your desktop?  Drive Monitor monitors drives on remote machines! Simply install the server on the machine you want to monitor and use the “Add Computer” button to start the monitoring process. (So easy a group highly trained monkeys working in tandem could do it!)

Supported Features

  • Remote Monitoring
  • Unlimited monitor sources
  • Multi-Threaded monitoring
  • Threshold Alarms / Alerts
  • View as Kilobytes, Megabytes, Gigabytes or Terabytes.
  • Special “Media Box Features” (View record hours left)
  • Each drive can have a diffrent view setting and a different threshold.

 

Requires the .Net v2 library be installed on the server(s) and the client(s) machines. This product is in the final stages of development, from there we proceed with the testing phase. If you are interested in becoming a tester please drop me an email, you can use the Contact feature of this blog.