Last active
April 10, 2018 01:33
-
-
Save jumbosushi/bb45922bcf25f58fed5b75df9239105e to your computer and use it in GitHub Desktop.
Download all 2018S CPSC322 files
This file contains hidden or 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
require "open-uri" | |
# Last lec is 23, first is 01 | |
# Ex Assignment link: https://www.cs.ubc.ca/~poole/cs322/2018/as1/as1.pdf | |
# EX Lec link: https://www.cs.ubc.ca/~poole/cs322/2018/slides/lect23s.pdf | |
def get_as_link(num) | |
return "https://www.cs.ubc.ca/~poole/cs322/2018/as#{num}/as#{num}.pdf" | |
end | |
def get_as_sol_link(num) | |
return "https://www.cs.ubc.ca/~poole/cs322/2018/as#{num}/as#{num}sol.pdf" | |
end | |
def get_lec_link(num) | |
return "https://www.cs.ubc.ca/~poole/cs322/2018/slides/lect#{num}s.pdf" | |
end | |
def download_file(name, link) | |
download = open(link) | |
IO.copy_stream(download, Dir.pwd + name) | |
end | |
as_dir_name = "assignmnets" | |
Dir.mkdir(as_dir_name) unless File.exist?(as_dir_name) | |
# Download assignments & solutions | |
(1..10).step(1) do |i| | |
begin | |
download_file("/#{as_dir_name}/as#{i}.pdf", get_as_link(i)) | |
rescue OpenURI::HTTPError | |
puts "404 for as#{i}.pdf" | |
end | |
begin | |
download_file("/#{as_dir_name}/as#{i}sol.pdf", get_as_sol_link(i)) | |
rescue OpenURI::HTTPError | |
puts "404 for as#{i}sol.pdf" | |
end | |
end | |
lec_dir_name = "lectures" | |
Dir.mkdir(lec_dir_name) unless File.exist?(lec_dir_name) | |
# Download lectures | |
(1..23).step(1) do |i| | |
begin | |
lect_n = "%02d" % i | |
download_file("/#{lec_dir_name}/lect#{lect_n}.pdf", get_lec_link(lect_n)) | |
rescue OpenURI::HTTPError | |
puts "404 for lect#{i}.pdf" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment