Last active
June 29, 2023 08:35
-
-
Save steshaw/175625afb2c3b11e41b6d93ea64a41d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env nix-shell | |
#! nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [http-conduit http-types bytestring])" -i runhaskell | |
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.tar.gz | |
{-# LANGUAGE BlockArguments #-} | |
{-# LANGUAGE ImportQualifiedPost #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Monad (forM) | |
import Data.ByteString qualified as B | |
import Data.ByteString.Lazy qualified as BL | |
import Data.Foldable | |
import Data.Functor ((<&>)) | |
import Network.HTTP.Simple | |
import Network.HTTP.Types | |
waybackUrl = "https://web.archive.org/web/20150528104756if_" | |
apldUrl = "http://www.nondot.org:80/sabre/Mirrored/AdvProgLangDesign" | |
baseUrl = waybackUrl <> "/" <> apldUrl | |
download :: (String, FilePath) -> IO () | |
download (url, file) = do | |
putStrLn $ "Downloading " <> file <> " ..." | |
req <- | |
parseRequest url | |
<&> setRequestHeader hUserAgent ["get-apld-finkel"] | |
response <- httpLBS req | |
if "application/pdf" `elem` getResponseHeader hContentType response | |
then BL.writeFile file $ getResponseBody response | |
else putStrLn "Hmm, not a PDF" | |
main :: IO () | |
main = do | |
traverse_ (download . urlFile) $ fm [0 :: Int .. 10] \i -> | |
let si = show i | |
in if i < 10 then "0" <> si else si | |
where | |
fm = flip map | |
urlFile num = | |
let file = "finkel" <> num <> ".pdf" | |
in (baseUrl <> "/" <> file, file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment