Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Weather Monitor on your Tray


  • Please log in to reply
2 replies to this topic

#1 GreenCan

GreenCan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 319 posts

Posted 20 June 2009 - 07:58 PM

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, 20 June 2009 - 09:45 PM.








#2 dantay9

dantay9

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 834 posts

Posted 20 June 2009 - 08:58 PM

I think you forgot to attach the _IniMem_Read.au3 script.
"Failure is not an option -- it comes packaged with Windows" Gecko Web Browser, Yahtzee!, Toolbar Launcher (like RocketDock)Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI Triangle Solver, TCP File Transfer, Valuater's Autoit WrappersOOP In AutoItUsing Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com

#3 GreenCan

GreenCan

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 319 posts

Posted 20 June 2009 - 09:46 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users