Powershell Script for Weather text overlay

Questions? Suggestions? Need help? Talk about anything related to Yawcam...
Post Reply
Yoda
Posts: 3
Joined: Thu Nov 24, 2011 5:40 am

Powershell Script for Weather text overlay

Post by Yoda »

I wrote a pretty sweet powershell script that grabs the current weather conditions from NOAA and generates a {weather}.txt file. It's fully customizable and easy to manipulate. It can be run as a scheduled task as well. Anyone interested? PM me.
Yoda
Posts: 3
Joined: Thu Nov 24, 2011 5:40 am

The Script

Post by Yoda »

Some one PM'd me and asked for the script. So I thought I'd share with everyone.....

This requires you have Powershell installed:

Here is the Script and Instructions:

Visit : http://www.weather.gov/xml/current_obs/

Locate your location and notice the code for your chosen weather station, for instance:

Kickapoo Downtown Airport (KCWC) - This location code is KCWC

Edit the ps1 file that you will save and change the URL where it says YOUR LOCATION CODE, to your location code. For instance:

Code: Select all

http://www.weather.gov/xml/current_obs/KCWC.xml
Save it as "weather.ps1" in %userprofile%\.yawcam\extravars

Code: Select all

[xml]$xml = (New-Object System.Net.WebClient).DownloadString("http://www.weather.gov/xml/current_obs/YOUR LOCATION CODE.xml?item=All")

$output_file = "%userprofile%\.yawcam\extravars\{weather}.txt"

$location = $xml.current_observation.location
$temp = $xml.current_observation.temp_f
$longitude = $xml.current_observation.longitude
$latitude =$xml.current_observation.latitude
$weather = $xml.current_observation.weather
$humid = $xml.current_observation.relative_humidity
$wind_detail = $xml.current_observation.wind_string
$wind_direction = $xml.current_observation.wind_dir
$wind_MPH = $xml.current_observation.wind_mph
$wind_chill = $xml.current_observation.windchill_f
$visibility = $xml.current_observation.visibility_mi
$dewpoint = $xml.current_observation.dewpoint_f
$pressure = $xml.current_observation.pressure_in

"$($temp)ºF - $($humid)% Humidity - Wind: $($wind_MPH)MPH - Wind Chill: $($wind_chill)ºF - Pressure $($pressure) - $($weather)" | out-file $output_file -encoding default
exit
You can add or remove variables in the last line to make it look however you want. Just follow the syntax already specified and use the variables from the list above. You may have to change %userprofile% on the output file variable declaration to the actual path instead of using the system variable. It's a very simple script.

In YawCam: Settings -> Edit Settings -> Overlay -> Text

- Enter {weather} as the text to be displayed, set the location, font etc. to your preference.

Create a scheduled task that runs this command every x minutes/hours, whatever you want...

Code: Select all

powershell -file %userprofile%\.yawcam\extravars\weather.ps1
Be sure to set it to start in the same folder as the script.
You can set it to run as the local computer administrator to hide the window.

It's a little Techy, hope you can follow. Nothing to terribly difficult. If you have a question about something Google is a great resource. ENJOY!
memoric
Posts: 184
Joined: Wed Feb 23, 2011 1:37 pm

Post by memoric »

Looks interesting, I'll check it out later. Thanks for sharing!
Btw, did you manage to display multi-lined text?
Coasterline
Posts: 4
Joined: Tue Sep 20, 2011 11:25 pm

Post by Coasterline »

This works perfectly. We currently have it in use with out outdoor webcam we have at: http://epicwebstudios.com/cam

Thanks again!
malun
Site Admin
Posts: 1593
Joined: Sun Jan 04, 2004 1:29 pm

Post by malun »

Thanks for sharing! :D
/malun
Post Reply