how to download pictures with wget

0

i would like to download pictures from http://myhomepage.com/plots/20150111-03/4711/4712.png every 3 hours. "20150111-03" is variable, rest is stable. That means every 3 hours the download looks like:

http:// myhomepage.com/plots/20150111-01/4711/4712.png --- http:// myhomepage.com/plots/20150111-02/4711/4712.png --- http:// myhomepage.com/plots/20150111-03/4711/4712.png

how i can manage this with wget (curl) and .bat file in windows?

bye Stefan

Stefan

Posted 2015-01-09T06:09:38.347

Reputation: 3

Answers

0

This should get you started

@echo off

:: Get current day month and year, padded with zeroes
for /f "skip=1 tokens=1-3 usebackq" %%a in (`wmic path Win32_LocalTime Get Day^,Month^,Year`) do (
    if not "%%c"=="" (
        set y=%%c
        set m=0%%b
        set d=0%%a
    )
)

set m=%m:~-2%
set d=%d:~-2%

:: Loop over image files, in this case, 100 of them
setlocal enabledelayedexpansion

for /L %%i in (1,1,100) do (
    set index=0%%i
    set index=!index:~-2!
    set url=http://myhomepage.com/plots/!y!!m!!d!-!index!/4711/4712.png
    wget -O "!y!!m!!d!-!index!.png" "!url!"
) 

endlocal enabledelayedexpansion

Berend

Posted 2015-01-09T06:09:38.347

Reputation: 1 824

thank you very much: this works! what i have to do if the time stamps are not every hour or 100 times but in this way: 20150109-00 20150109-03 20150109-06 20150109-09 20150109-12 20150109-15 20150109-18 20150109-21

and for the next 3 days?

bye – Stefan – 2015-01-09T21:28:52.597

In that case you should type 'help for', and see that you can set a step value in the for loop, e.g. 'for /L %%i in (1,3,100)'. Doing the next three days is harder: you could loop over current day, +1, +2, but you'd also need logic to go into a new month or year. – Berend – 2015-01-12T08:58:14.280