::::::::: PowerShell :::::::::
Monday, November 07, 2005
  Displaying Weather Info through RSS with MSH
Uhm, I have been trying to display Weather data through MSH scripting.
Man, after struggling for 30 minutes, i got kind of tired and didn't event get to finish the fully working demo.

I just have pasted something i have been fiddling around a bit(WARNING: hardcore hardcoding)

Most of Form window code was copied from MSH directory watcher with popup-balloon and RSS part can be found from Monad and RSS, Part 2

I was having trouble with getting a description for each "$rssData.rss.channel.item". The description was in "CData" form and it wouldn't let me access the property named "#cdata-section". I guess i just don't know how to access the property... Bah, time to go and hit the usenet...


[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

function weather {
$form = new-object System.Windows.Forms.Form
$cm = new-object System.Windows.Forms.ContextMenu
$miExit = new-object System.Windows.Forms.MenuItem
$miRefresh = new-object System.Windows.Forms.MenuItem
$ni = new-object System.Windows.Forms.NotifyIcon

$form.ContextMenu = $cm
$form.ContextMenu.MenuItems.Add($miRefresh)
$form.ContextMenu.MenuItems.Add($miExit)
$form.ShowInTaskbar = $false
$form.WindowState = "minimized"
$form.add_Load({
$wc = new-object System.Net.WebClient
$uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&weadegreetype=F"
$rssData = [xml] $wc.DownloadString($uri)

$title = $rssData.rss.channel.title
$desc = $rssData.rss.channel.item[0].title

$ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")
})

$ni = $ni
$ni.Icon = new-object System.Drawing.Icon("c:\msh\icons\test.ico")
$ni.ContextMenu = $cm

$miRefresh.Index = 0
$miRefresh.Text = "&Refresh"
$miRefresh.add_Click({
$wc = new-object System.Net.WebClient
$uri = "http://weather.msn.com/RSS.aspx?wealocations=wc:USNY0833&weadegreetype=F"
$rssData = [xml] $wc.DownloadString($uri)

$title = $rssData.rss.channel.title
$desc = $rssData.rss.channel.item[0].title

$ni.ShowBalloonTip(100, $title, $desc, [system.windows.forms.ToolTipIcon]"Info")
})

$miExit.Index = 1
$miExit.Text = "E&xit"
$miExit.add_Click({ $form.Close() })

$ni.visible = $true
$form.showDialog()
}

weather
 
Comments: Post a Comment

Links to this post:

Create a Link



<< Home
Let's get lazy with PowerShell!

Name:
Location: Flushing, NY, United States

Experimenting with a different format of blogs...

Links
ARCHIVES
10/01/2005 - 11/01/2005 / 11/01/2005 - 12/01/2005 / 12/01/2005 - 01/01/2006 / 01/01/2006 - 02/01/2006 / 02/01/2006 - 03/01/2006 / 03/01/2006 - 04/01/2006 / 04/01/2006 - 05/01/2006 / 05/01/2006 - 06/01/2006 / 06/01/2006 - 07/01/2006 / 07/01/2006 - 08/01/2006 / 08/01/2006 - 09/01/2006 / 10/01/2006 - 11/01/2006 / 11/01/2006 - 12/01/2006 /


Powered by Blogger