Skip to content

Instantly share code, notes, and snippets.

@eungju
Last active April 9, 2019 08:31
Show Gist options
  • Save eungju/fdee7ae248a7d4d8a1f0 to your computer and use it in GitHub Desktop.
Save eungju/fdee7ae248a7d4d8a1f0 to your computer and use it in GitHub Desktop.
Download The Art of Science and Engineering
import Control.Applicative
import Control.Monad
import System.Directory
import System.FilePath
import System.Exit
import System.Process
import Text.Printf
type URL = String
makeURL :: String -> URL
makeURL = printf "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/chapters/Hamming%s.pdf"
download :: FilePath -> URL -> IO ()
download targetDir url = do
exitCode <- system $ printf "wget --no-check-certificate -nc -P '%s' '%s'" targetDir url
when (exitCode /= ExitSuccess) $
fail (printf "Cannot download %s." url)
main :: IO ()
main = do
targetDir <- flip combine "chapters" <$> getCurrentDirectory
createDirectoryIfMissing True targetDir
forM_ ("Biography":map (printf "%02d" :: Int -> String) [1..30]) $ \name ->
download targetDir $ makeURL name
pdf_pattern = "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/chapters/Hamming%s.pdf"
(["Biography"] + (0..30).map { |i| sprintf("%02d", i) }).each { |i|
system("wget", "-P", "chapters", sprintf(pdf_pattern, i))
}
import Control.Applicative
import Control.Monad
import System.Directory
import System.FilePath
import System.Exit
import System.Process
import Text.Printf
type URL = String
makeURL :: String -> String -> URL
makeURL name ext = printf "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/Hamming%s.%s" name ext
download :: FilePath -> URL -> IO ()
download targetDir url = do
exitCode <- system $ printf "wget --no-check-certificate -nc -P '%s' '%s'" targetDir url
when (exitCode /= ExitSuccess) $
fail (printf "Cannot download %s." url)
main :: IO ()
main = do
targetDir <- flip combine "lectures" <$> getCurrentDirectory
createDirectoryIfMissing True targetDir
download targetDir "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/CourseIntroductionBrutzman7January2006.6.mov"
download targetDir (makeURL "00Introduction" "mov")
forM_ (map (printf "%02d" :: Int -> String) [0..30]) $ \name ->
forM_ ["mov", "ppt", "pdf"] $ \ext ->
download targetDir $ makeURL name ext
def download(url, d)
system("wget", "-P", d, url)
end
mov_pattern = "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/Hamming%s.mov"
ppt_pattern = "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/Hamming%s.ppt"
pdf_pattern = "https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/Hamming%s.pdf"
download("https://savage.nps.edu/hamming/HammingLearningToLearnRecovered/CourseIntroductionBrutzman7January2006.6.mov", "lectures")
download(sprintf(mov_pattern, "00Introduction"), "lectures")
(0..30).map { |i| sprintf("%02d", i) }.each { |i|
[mov_pattern, ppt_pattern, pdf_pattern].each { |p|
download(sprintf(p, i), "lectures")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment