Jump to content

Weather Monitor on your Tray


GreenCan
 Share

Recommended Posts

This is a Weather Monitor running on the system tray. OK, there were already quite some examples on the forum but this one is working worldwide as far as I know.

It's a pretty old script that I wrote last winter and it's running on my test server since almost 7 months without any interruption, and is still doing fine. As it never crashed, it's obviously stable.

So, it could be the right time to publish the code now...

What does it do:

Displays the weather from right to left in the currently active Windows Title bar:

Actual weather Brussels: Mostly Cloudy 16°C - Relative Humidity: 57% - Visibility: 9.99 km - Wind: WNW 6 kph - Pressure: 1023 mb, steady...

Afterwards, it restores the original Windows Title

Or if there is no Actve Window open, it displays a TrayTip containing slightly more information:

Actual weather for Brussels, BE:

Conditions as of 8:00 pm CEST

Mostly Cloudy 16°C

Relative Humidity: 57%

Visibility: 9.99 km

Wind: WNW 6 kph

Pressure: 1023 mb, steady

Forecast:

Sun, 21 Jun 2009: Low 10°C, High 18°C, AM Light Rain

If HistoryFile=1 in WeatherTray.ini, each time the temperature, cloud cast or humidity changes, it will register the change in a csv file

11/06/2009, 04:31, 12°C, 94%, Fog

11/06/2009, 05:47, 12°C, 94%, Mostly Cloudy

11/06/2009, 06:02, 12°C, 88%, Light Rain

11/06/2009, 06:47, 11°C, 94%, Heavy Rain

11/06/2009, 07:17, 12°C, 88%, Mostly Cloudy

11/06/2009, 07:47, 12°C, 94%, Mostly Cloudy

11/06/2009, 08:03, 12°C, 88%, Light Rain

11/06/2009, 08:48, 12°C, 94%, Cloudy

Compatibility

Tested on Windows XP and Vista

On Vista, the scrolling message doesn't function as there is no identifiable title bar, the traytip always works.

Source of the weather data:

RSS Feed of Yahoo

http://weather.yahooapis.com/forecastrss?p=BEXX0005

where BEXX0005 = the code for Brussels, Belgium

More information at

http://developer.yahoo.com/weather/

How to find your City:

Example for New-York

- Goto http://weather.yahoo.com/

- Search for New-York

- Select Brooklyn

Resulting url:

http://weather.yahooapis.com/forecastrss?p=USNY0176

USNY0176 is the code for New-York, Brooklyn

The RSS Feed is:

http://weather.yahooapis.com/forecastrss?p=USNY0176

How does it function:

The script has been designed to consume as less memory as possible.

In sleep mode, WeatherTray consupmes about 980K-1.300K

In fetch and display mode, it requires 2.500-4.000K (just take a look at what your MSIE is eating from your resources)

It can thus stay on your tray without effect for your other apps.

Any defined number of minutes, the script will wake up and fetch the latest weather from Yahoo RSS and display it.

With a mouseclick on the icon, you can also force the TrayTip if you like

You can also exit via the icon.

The csv file will always contain the name of the City as shown on Yahoo:

Weather History Brussels.csv (for Brussels)

When you change the City in the ini file, a new csv will be created.

Content of ini file:

There is no editing module of the ini file. So you will have to take notepad and edit it. I have no intention to write

[Yahoo_RSS] ==>this is the Yahoo sections header

url=http://weather.yahooapis.com/forecastrss?p= ==>The url of Yahoo RSS without the city code

Town_code=xxxxxxxx ==>The City Code

Degrees=x ==> C = degrees in Celsius, F = degrees in Farenheit

will also convert respectively km to mi, kph to mph, mb to in

Display_frequency=## ==> Display The Weather every x Minutes

HistoryFile=# ==> 0 = Do not keep, 1 = write history to csv file

If option is set to 1. a csv file will be created in the script directory.

Every change (Temperature, Relative Humidity, Sky) will be saved

#Show=Country,Humidity,Wind,Visibility,Forecast,Pressure

Show=Wind,Visibility,Humidity,Pressure ==>Show items in title bar scrolling message (the longer, the slower

Country: display country code

Humidity: display humidity information

Wind: display wind wind information

Visibility: display visibility

Forecast: display forecast next day

Pressure: display Pressure information

This last items is also optional in the tray too because 'sometimes' the result will be 0 if degree Celsius is selected (due to a bug in Yahoo!)

WeatherTray.ini

CODE
[Yahoo_RSS]

url=http://weather.yahooapis.com/forecastrss?p=

Town_code=BEXX0005

Degrees=c

Display_frequency=15

HistoryFile=1

#Show=Country,Humidity,Wind,Visibility,Forecast,Pressure

Show=Wind,Visibility,Humidity,Pressure

Useful? Probably not :huh:

Funny? Only when it rains ^_^

Should you put it on your desktop? If you can't lift your head and look outside the window, maybe you should... :lol:

Enjoy it

GreenCan

WeatherTray.au3[autoit]#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.12.1

Author: GreenCan, Nov 2008

Display a the current weather at ... in the active window's title bar

#ce ----------------------------------------------------------------------------

#cs

This is the content that is analysed:

<yweather:location city="Brussels" region="" country="BE"/>

<yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/>

<yweather:wind chill="-1" direction="290" speed="11.27" />

<yweather:atmosphere humidity="93" visibility="9.99" pressure="0" rising="0" />

<yweather:astronomy sunrise="8:33 am" sunset="4:37 pm"/>

<image>

<title>Yahoo! Weather</title>

<width>142</width>

<height>18</height>

<link>http://weather.yahoo.com</link>

<url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>

</image>

<item>

<title>Conditions for Brussels, BE at 7:20 pm CET</title>

<geo:lat>50.9</geo:lat>

<geo:long>4.53</geo:long>

<link>http://us.rd.yahoo.com/dailynews/rss/weather/Brussels__BE/*http://weather.yahoo.com/forecast/BEXX0005_c.html</link>

<pubDate>Tue, 09 Dec 2008 7:20 pm CET</pubDate>

<yweather:condition text="Fair" code="33" temp="2" date="Tue, 09 Dec 2008 7:20 pm CET" />

<description><![CDATA[

<img src="http://l.yimg.com/us.yimg.com/i/us/we/52/33.gif"/><br />

<b>Current Conditions:</b><br />

Fair, 2 C<BR />

<BR /><b>Forecast:</b><BR />

Tue - Showers. High: 3 Low: 1<br />

Wed - Partly Cloudy. High: 4 Low: 0<br />

<br />

<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Brussels__BE/*http://weather.yahoo.com/forecast/BEXX0005_c.html">Full Forecast at Yahoo! Weather</a><BR/>

(provided by The Weather Channel)<br/>

]]></description>

<yweather:forecast day="Tue" date="9 Dec 2008" low="1" high="3" text="Showers" code="11" />

<yweather:forecast day="Wed" date="10 Dec 2008" low="0" high="4" text="Partly Cloudy" code="30" />

<guid isPermaLink=

#ce

#NoTrayIcon

#include <INet.au3>

#include <String.au3>

#include <array.au3>

#include "Misc.au3"

#include <_IniMem_Read.au3>

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

TraySetIcon(@ScriptDir & "\Weather2.ico")

TraySetToolTip ("Weather Monitor" )

if _Singleton(@ScriptName,1) = 0 Then

Opt("TrayIconHide", 1)

Msgbox(0,"Warning",@ScriptName & " is already running",3)

Exit

EndIf

Global $keep_temp="unk"

; ini file expected in the same directory as the script

$iniFile=@ScriptDir & "\WeatherTray.ini"

; put sections in array

$var = IniReadSectionNames($iniFile)

If @error Then

MsgBox(48, "Error", "Error occurred while trying to open " & $iniFile)

Exit

Else

; Open the ini file in memory

$FileHandle = FileOpen($iniFile, 0)

$inifile = FileRead($FileHandle)

$filesys = ObjCreate( "Scripting.FileSystemObject" )

$url = _IniMem_Read($inifile, "Yahoo_RSS", "url")

$Town_code = _IniMem_Read($inifile, "Yahoo_RSS", "Town_code")

$Degrees = _IniMem_Read($inifile, "Yahoo_RSS", "Degrees")

$Traytip_Minutes = _IniMem_Read($inifile, "Yahoo_RSS", "Display_frequency")

$HistoryFile = _IniMem_Read($inifile, "Yahoo_RSS", "HistoryFile")

$Show = _IniMem_Read($inifile, "Yahoo_RSS", "Show")

If $HistoryFile = 1 Then

$HistoryFile = True

Else

$HistoryFile = False

EndIf

FileClose($FileHandle)

EndIf

$ActualWeatherItem = TrayCreateItem("Actual Weather")

TrayCreateItem("")

$aboutitem = TrayCreateItem("About")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

_ReduceMemory()

; initiate timer

Local $60Count = 1, $begin = TimerInit(), $Minutes = 0.1 ; display first tooltip anyway

TraySetState()

While 1

$msg = TrayGetMsg()

If $Minutes>0 Then ; only when $Minutes > 0

$dif = TimerDiff($begin)

$dif2 = StringLeft($dif, StringInStr($dif, ".") -1)

$Count = int($dif/1000)

$60Count = Round($Count / 60,1); Int($Count / 60)

If $Minutes < $60Count Then

$window_title = tipper("WinTitle")

$result = _WinSetTitleScroll($window_title,'',50)

if $result = -1 Then ; no active window so display the TrayTip instead

TrayTip("","Querying server...",0)

$tray_tip = tipper("Tray")

TrayTip("",$tray_tip, 0, 1+16)

EndIf

_ReduceMemory()

$Minutes = $Traytip_Minutes ; Now pick up the timer from the ini file, if 0 the TrayTip will not be displayed anymore

$60Count = 0

$begin = TimerInit()

EndIf

EndIf

Select

Case $msg = $ActualWeatherItem

; force show TrayTip and rest timer

TrayTip("","Querying server...",0)

$tray_tip = tipper("Tray")

TrayTip("",$tray_tip, 0, 1+16)

_ReduceMemory()

Case $msg = 0

ContinueLoop

Case $msg = $aboutitem

TrayTip("Weather Monitor","By GreenCan" & @cr & "RSS feedfrom Yahoo!" & @cr &"Dec 2008", 0, 1+16)

_ReduceMemory()

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Exit

#FUNCTION# ==============================================================

Func _ReduceMemory()

Local $dll_mem = DllOpen(@SystemDir & "\psapi.dll")

Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1)

If @error Then Return SetError(@error, @error, 1)

Return $ai_Return[0]

EndFunc ;==>_ReduceMemory

#FUNCTION# ==============================================================

Func tipper($Method)

$Temp = "?"

$Relative_humidity = "?"

$Pressure = "?"

$City = "?"

$File = _INetGetSource($url & $Town_Code & "&u=" & $Degrees)

if @ERROR = 1 then Return ("Internet down or Yahoo RSS feed not available")

; now extract part of interest

$TempArray1 = _StringBetween($File, '<yweather:location ', 'isPermaLink')

; City

$TempArray = _StringBetween($TempArray1[0], 'city="', '" region=')

If $TempArray <> 0 Then

$City = $TempArray[0]

Else

$City = "N/A"

EndIf

; Country

$TempArray = _StringBetween($TempArray1[0], 'country="', '"/>')

If $TempArray <> 0 Then

$Country = $TempArray[0]

Else

$Country = "N/A"

EndIf

; units

$TempArray = _StringBetween($TempArray1[0], '<yweather:units ', '<yweather:wind')

; temperature_unit

$TempArray2 = _StringBetween($TempArray[0], 'temperature="', '" distance')

If $TempArray2 <> 0 Then

$temperature_unit = $TempArray2[0]

Else

$temperature_unit = "N/A"

EndIf

; visibility_unit

$TempArray2 = _StringBetween($TempArray[0], 'distance="', '" pressure=')

If $TempArray2 <> 0 Then

$visibility_unit = $TempArray2[0]

Else

$visibility_unit = "N/A"

EndIf

; pressure_unit

$TempArray2 = _StringBetween($TempArray[0], 'pressure="', '" speed=')

If $TempArray2 <> 0 Then

$pressure_unit = $TempArray2[0]

Else

$pressure_unit = "N/A"

EndIf

; windspeed_unit

$TempArray2 = _StringBetween($TempArray[0], 'speed="', '"/>')

If $TempArray2 <> 0 Then

$windspeed_unit = $TempArray2[0]

Else

$windspeed_unit = "N/A"

EndIf

; Cloud_cast

$TempArray = _StringBetween($TempArray1[0], '<yweather:condition text="', '" code=')

If $TempArray <> 0 Then

$Cloud_cast = $TempArray[0]

Else

$Cloud_cast = "N/A"

EndIf

; Time

$TempArray = _StringBetween($TempArray1[0], ' at ', '</title>')

If $TempArray <> 0 Then

$Date_time = $TempArray[0]

Else

$Date_time = "N/A"

EndIf

; Temperature

$TempArray = _StringBetween($TempArray1[0], 'temp="', '" date')

If $TempArray <> 0 Then

$Temp = $TempArray[0] & "

Edited by GreenCan

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Link to comment
Share on other sites

I think you forgot to attach the _IniMem_Read.au3 script.

Right,

Thanks, it's an uf from Alec, although it can be found on this forum, I attached it on my first post

GreenCan

Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...