fetch_himawari.cmd 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. @if (@CodeSection == @Batch) @then
  2. @echo off & setlocal
  3. SETLOCAL ENABLEDELAYEDEXPANSION
  4. set PROCS="%~dp0procs.cmd"
  5. set "url=http://www.ssec.wisc.edu/data/geo-new/images/himawari08/animation_images"
  6. for /f "usebackq tokens=* delims=" %%I in ( `powershell get-date((get-date^).addDays(-1^)^) -uformat "%%d.%%m.%%Y"` ) do set "DMY=%%I"
  7. for /f "usebackq tokens=* delims=" %%I in ( `call %PROCS% DAYNUM %DMY%` ) do set "DN=%%I"
  8. set "filter=himawari08_%date:~6,4%%DN%_...._rgb_fd\.jpg"
  9. @echo.Fetching files for %DMY% day of year %DN% filename: %filter%
  10. for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" "%url%" "%filter%"') do (
  11. rem // do something useful with %%I
  12. set /a COUNTER+=1
  13. set /a PTS= 100*!COUNTER!/142
  14. echo.
  15. @echo !COUNTER!.%url%/%%I
  16. curl -f -o "f:\himawari\%%I" %url%/%%I || @echo.Process failed. Error:!ERRORLEVEL!
  17. @echo.!PTS!^%% done.
  18. )
  19. rem pause
  20. goto :EOF
  21. @end // end batch / begin JScript hybrid code
  22. // returns a DOM root object
  23. function fetch(url) {
  24. var XHR = WSH.CreateObject("Microsoft.XMLHTTP"),
  25. DOM = WSH.CreateObject('htmlfile');
  26. XHR.open("GET", url, true);
  27. XHR.setRequestHeader( 'User-Agent', 'XMLHTTP/1.0' );
  28. XHR.send('');
  29. while (XHR.readyState!=4) { WSH.Sleep(25) };
  30. DOM.write('<meta http-equiv="x-ua-compatible" content="IE=9" />');
  31. DOM.write(XHR.responseText);
  32. return DOM;
  33. }
  34. var DOM = fetch(WSH.Arguments(0)),
  35. links = DOM.getElementsByTagName('a');
  36. var pattern = new RegExp(WSH.Arguments(1), i);
  37. for (var i in links)
  38. if (links[i].href && pattern.test(links[i].href)) WSH.Echo(links[i].pathname);