Guest User

localize_gutenberg_book.cmd

a guest
Jul 9th, 2017
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.83 KB | None | 0 0
  1. @echo off
  2. rem saveBook from gutenberg.spiegel.de
  3. setlocal EnableDelayedExpansion
  4. set "bookTitle=ulenspiegel"
  5. rem  die erste Seite des  buchs ist http://gutenberg.spiegel.de/buch/ulenspiegel-2462/1  
  6. rem  die 1 wird weggelassen  und  durch die Seitennummer ersetzt
  7. set "GutenbergBaseUrl=http://gutenberg.spiegel.de/buch/ulenspiegel-2462/"
  8. set "textBlockStart=\<div id=\"gutenb\"\>"
  9. set "textBlockEnd=\<\/div\>"
  10. set /a "firstSubsite=1"
  11. set /a "lastSubsite=14"
  12. set "destinationPath=%~dp0savedSites"
  13. md "%destinationPath%" 2>nul
  14. set destinationFile=%destinationPath%\%bookTitle%
  15. set "finalHtmlFile=%destinationPath%\%bookTitle%.html
  16.  
  17. :main
  18. rem alle Webseiten die  zum Buch gehören lokal speichern
  19. for /l %%c in (%firstSubsite%,1,%lastSubsite%) do (
  20. call  :saveSites "%GutenbergBaseUrl%%%c"  "%destinationFile%%%c.txt"
  21. )
  22.  
  23. rem neue Html-Seite erzeugen
  24. echo ^<html^> >"%finalHtmlFile%"
  25. echo   ^<body^> >>"%finalHtmlFile%"
  26. rem den Inhalt des  div-containers   <div id="gutenb">"  in jeder runtergeladenen Webseite in die  neue locale webseite schreiben.
  27. for /l %%c in (%firstSubsite%,1,%lastSubsite%) do (
  28. call :parse "%destinationFile%%%c.txt"
  29. )
  30. echo   ^<body^> >>"%finalHtmlFile%"
  31. echo ^<html^> >>"%finalHtmlFile%"
  32. echo fertig
  33. start "" "%finalHtmlFile%"
  34. pause
  35. exit
  36.  
  37. :saveSites
  38. echo download  %1 to %~nx2
  39. powershell -command "&{$url = '%~1';$path = '%~2';$client = New-Object System.Net.WebClient;$client.DownloadFile($url, $path)}"
  40. exit /b
  41.  
  42.  
  43. :parse
  44. call :find1stLine2read "%~1"
  45. for /F "skip=%firstLine2Read% delims=" %%a in ('type "%~1"') do (
  46. set nixdummy=%%a
  47. set nixdummy|FINDSTR /ic:"\<\/div\>" >nul && goto breakParse|| echo. %%a >>"%finalHtmlFile%" & echo. %%a
  48. )
  49. :breakParse
  50. exit /b
  51.  
  52. :find1stLine2read
  53. for /f "usebackq delims=:" %%a in (`findstr /nic:"%textBlockStart%" "%~1"`) do (
  54.   set /a "firstLine2Read=%%a"
  55. )
  56. exit /b
Advertisement
Add Comment
Please, Sign In to add comment