Last active
April 9, 2019 08:31
-
-
Save eungju/fdee7ae248a7d4d8a1f0 to your computer and use it in GitHub Desktop.
Download The Art of Science and Engineering
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
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 |
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
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)) | |
} |
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
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 |
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
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