Sign in to follow this  
Followers 0
llewxam

Weather Channel image saver

3 posts in this topic

Dunno about you, but I like watching time lapse videos and thought it would be cool to save some radar and satellite images from The Weather Channel to string in to slideshows. Here is a script I have put together over the last few days, a few tweaks at a time, hopefully some other people dig on it, too.

On average it is saving about 90 or so images from each of the 3 categories I have it pulling. To explain about the code, I have it pull images from TWC's website every 4 minutes, it seems a good amount of time between checks, it looks like most of the time images get updated on their end at least every 7 minutes. One quirk though is that in the early versions of this script, I was getting updates every minute and found that their servers seem to go back and forth between the newest picture and the previous one, so I had to come up with a way of making sure the image should be saved. Much thanks to "monoceres" for the code in post http://www.autoitscript.com/forum/index.php?showtopic=89690&view=findpost&p=644671 that I used for the comparison of the images! Annoyingly, TWC's little back-and-forth can happen several times, so I have it check against the last 8 images found, hence the need for the ini file.

So, long description for a fairly simple idea. Enjoy.

Ian

#include <GDIPlus.au3>
Global $fname1,$fname2 ;   $fname1=temp pic                        $fname2=pics to compare against
Global $dirty,$filthy  ;   $dirty=per image unique or same         $filthy=per group of images checked unique or same
$savedir="C:\Weather Images\Weather Channel"
$ini=@scriptdir&"\Weather.ini"

If Not FileExists($ini) Then ; set up the ini
    IniWrite($ini,"Last Update","Time",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"Last Update","Time To Update","1 Second")
    IniWrite($ini,"US Doppler","Time 1",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 2",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 3",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 4",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 5",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 6",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 7",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Doppler","Time 8",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 1",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 2",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 3",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 4",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 5",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 6",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 7",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"NE Doppler","Time 8",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 1",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 2",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 3",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 4",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 5",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 6",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 7",@YEAR&@MON&@MDAY&@HOUR&@MIN)
    IniWrite($ini,"US Satellite","Time 8",@YEAR&@MON&@MDAY&@HOUR&@MIN)
EndIf

takepic() ; grab a current pic to get started
$begin=TimerInit() ; start the clock for updating



Do ; timing loop
    If TimerDIff($begin)>240000 Then takepic() ; runs every 4 minutes
Until 1=2



Func takepic()

    $updatetime=TimerInit() ; used to time the updating process
    $time=@YEAR&@MON&@MDAY&@HOUR&@MIN
    InetGet("http://image.weather.com/web/radar/us_ne_4regradar_plus_usen.jpg",@TempDir&"\"&$time&".jpg",1)
    $fname1=@TempDir&"\"&$time&".jpg"
    $checknum=9 ; the last 8 pics are compared to the current grab, start with 9 since 1 comes off right away
    $filthy=0 ; reset $filthy flag

    Do
        $checknum-=1 ; start with the most recent saved pic and work backwards
        $fname2=$savedir&"\Northeast Doppler\"&IniRead($ini,"NE Doppler","Time "&$checknum&"","unknown")&".jpg"
        If FileExists($fname2) Then check() ; compare the last saved pic to the current
        If $dirty=1 Then $filthy=1 ; if any files match Then $filthy is set, which means don't save the current pic
    Until $checknum=1
    If $filthy=0 Then ; If it is a unique pic
        FileCopy($fname1,$savedir&"\Northeast Doppler\"&$time&".jpg",8)
        IniWrite($ini,"NE Doppler","Time 1",IniRead($ini,"NE Doppler","Time 2","unknown")) ; "Time 8" is the newest, so
        IniWrite($ini,"NE Doppler","Time 2",IniRead($ini,"NE Doppler","Time 3","unknown")) ; this section moves all of the
        IniWrite($ini,"NE Doppler","Time 3",IniRead($ini,"NE Doppler","Time 4","unknown")) ; time stamps in the ini one down
        IniWrite($ini,"NE Doppler","Time 4",IniRead($ini,"NE Doppler","Time 5","unknown"))
        IniWrite($ini,"NE Doppler","Time 5",IniRead($ini,"NE Doppler","Time 6","unknown"))
        IniWrite($ini,"NE Doppler","Time 6",IniRead($ini,"NE Doppler","Time 7","unknown"))
        IniWrite($ini,"NE Doppler","Time 7",IniRead($ini,"NE Doppler","Time 8","unknown"))
        IniWrite($ini,"NE Doppler","Time 8",$time) ; newest pic
    EndIf


    InetGet("http://image.weather.com/web/radar/us_radar_plus_usen.jpg",@TempDir&"\"&$time&".jpg",1)
    $fname1=@TempDir&"\"&$time&".jpg"
    $checknum=9
    
    $filthy=0
    Do
        $checknum-=1
        $fname2=$savedir&"\US Doppler\"&IniRead($ini,"US Doppler","Time "&$checknum&"","unknown")&".jpg"
        If FileExists($fname2) Then check()
        If $dirty=1 Then $filthy=1
    Until $checknum=1
    If $filthy=0 Then
        FileCopy($fname1,$savedir&"\US Doppler\"&$time&".jpg",8)
        IniWrite($ini,"US Doppler","Time 1",IniRead($ini,"US Doppler","Time 2","unknown"))
        IniWrite($ini,"US Doppler","Time 2",IniRead($ini,"US Doppler","Time 3","unknown"))
        IniWrite($ini,"US Doppler","Time 3",IniRead($ini,"US Doppler","Time 4","unknown"))
        IniWrite($ini,"US Doppler","Time 4",IniRead($ini,"US Doppler","Time 5","unknown"))
        IniWrite($ini,"US Doppler","Time 5",IniRead($ini,"US Doppler","Time 6","unknown"))
        IniWrite($ini,"US Doppler","Time 6",IniRead($ini,"US Doppler","Time 7","unknown"))
        IniWrite($ini,"US Doppler","Time 7",IniRead($ini,"US Doppler","Time 8","unknown"))
        IniWrite($ini,"US Doppler","Time 8",$time)
    EndIf


    InetGet("http://image.weather.com/images/sat/ussat_600x405.jpg",@TempDir&"\"&$time&".jpg",1)
    $fname1=@TempDir&"\"&$time&".jpg"
    $checknum=9
    
    $filthy=0
    Do
        $checknum-=1
        $fname2=$savedir&"\US Satellite\"&IniRead($ini,"US Satellite","Time "&$checknum&"","unknown")&".jpg"
        If FileExists($fname2) Then check()
        If $dirty=1 Then $filthy=1
    Until $checknum=1
    If $filthy=0 Then
        FileCopy($fname1,$savedir&"\US Satellite\"&$time&".jpg",8)
        IniWrite($ini,"US Satellite","Time 1",IniRead($ini,"US Satellite","Time 2","unknown"))
        IniWrite($ini,"US Satellite","Time 2",IniRead($ini,"US Satellite","Time 3","unknown"))
        IniWrite($ini,"US Satellite","Time 3",IniRead($ini,"US Satellite","Time 4","unknown"))
        IniWrite($ini,"US Satellite","Time 4",IniRead($ini,"US Satellite","Time 5","unknown"))
        IniWrite($ini,"US Satellite","Time 5",IniRead($ini,"US Satellite","Time 6","unknown"))
        IniWrite($ini,"US Satellite","Time 6",IniRead($ini,"US Satellite","Time 7","unknown"))
        IniWrite($ini,"US Satellite","Time 7",IniRead($ini,"US Satellite","Time 8","unknown"))
        IniWrite($ini,"US Satellite","Time 8",$time)
    EndIf

    IniWrite($ini,"Last Update","Time",$time)
    IniWrite($ini,"Last Update","Time To Update",Round((TimerDIff($updatetime)/1000),2)&" Seconds")
    
    $begin=TimerInit()

EndFunc ; takepic()



Func check()

    _GDIPlus_Startup()
    $bm1 = _GDIPlus_ImageLoadFromFile($fname1)
    $bm2 = _GDIPlus_ImageLoadFromFile($fname2)

    If CompareBitmaps($bm1, $bm2)=1 Then $dirty=1 ; the images being compared are the same
    If CompareBitmaps($bm1, $bm2)=0 Then $dirty=0 ; the images being compared are different
    _GDIPlus_ImageDispose($bm1)
    _GDIPlus_ImageDispose($bm2)
    _GDIPlus_Shutdown()

EndFunc ; check()

Func CompareBitmaps($bm1, $bm2)
    
    $Bm1W = _GDIPlus_ImageGetWidth($bm1)
    $Bm1H = _GDIPlus_ImageGetHeight($bm1)
    $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData1, "Stride")
    $Scan0 = DllStructGetData($BitmapData1, "Scan0")
    
    $ptr1 = $Scan0
    $size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4
    
    $Bm2W = _GDIPlus_ImageGetWidth($bm2)
    $Bm2H = _GDIPlus_ImageGetHeight($bm2)
    $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData2, "Stride")
    $Scan0 = DllStructGetData($BitmapData2, "Scan0")
    
    $ptr2 = $Scan0
    $size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
    
    $smallest = $size1
    If $size2 < $smallest Then $smallest = $size2
    $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)

    _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
    _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
    
    Return ($call[0]=0)
        
EndFunc  ;CompareBitmaps()

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites



May I know what kind of image compare are you doing?

Func CompareBitmaps($bm1, $bm2)
    
    $Bm1W = _GDIPlus_ImageGetWidth($bm1)
    $Bm1H = _GDIPlus_ImageGetHeight($bm1)
    $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData1, "Stride")
    $Scan0 = DllStructGetData($BitmapData1, "Scan0")
    
    $ptr1 = $Scan0
    $size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4
    
    $Bm2W = _GDIPlus_ImageGetWidth($bm2)
    $Bm2H = _GDIPlus_ImageGetHeight($bm2)
    $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData2, "Stride")
    $Scan0 = DllStructGetData($BitmapData2, "Scan0")
    
    $ptr2 = $Scan0
    $size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
    
    $smallest = $size1
    If $size2 < $smallest Then $smallest = $size2
    $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)

    _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
    _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
    
    Return ($call[0]=0)
        
EndFunc  ;CompareBitmaps()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

May I know what kind of image compare are you doing?

Func CompareBitmaps($bm1, $bm2)
    
    $Bm1W = _GDIPlus_ImageGetWidth($bm1)
    $Bm1H = _GDIPlus_ImageGetHeight($bm1)
    $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData1, "Stride")
    $Scan0 = DllStructGetData($BitmapData1, "Scan0")
    
    $ptr1 = $Scan0
    $size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4
    
    $Bm2W = _GDIPlus_ImageGetWidth($bm2)
    $Bm2H = _GDIPlus_ImageGetHeight($bm2)
    $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
    $Stride = DllStructGetData($BitmapData2, "Stride")
    $Scan0 = DllStructGetData($BitmapData2, "Scan0")
    
    $ptr2 = $Scan0
    $size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
    
    $smallest = $size1
    If $size2 < $smallest Then $smallest = $size2
    $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)

    _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
    _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
    
    Return ($call[0]=0)
        
EndFunc  ;CompareBitmaps()

Go to the link in the first post, that's where I got it from. I don't understand GDI code so really I haven't got a clue what it is doing, but I do know that it can compare 3 new images against 24 old images on a P2 450MHz (my fileserver) in about 5 seconds! >_< And that includes the time to download the image which of course his code has nothing to do with, so pretty fast comparison.

Perhaps ask monoceres for a more detailed explaination if you are interested in the inner workings. All I did was make a couple very minor changes to fit in with my code, so all credit (and questions :( ) go to him. hahaha

Ian

Edited by llewxam

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
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
Sign in to follow this  
Followers 0