-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprecheck.rb
More file actions
37 lines (31 loc) · 781 Bytes
/
precheck.rb
File metadata and controls
37 lines (31 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require "open-uri"
require "csv"
SRC_PATH = File.expand_path(File.dirname(__FILE__))
CSV_FILE = "_data/members.csv"
PATH_TO_CSV = File.join SRC_PATH, CSV_FILE
STATIC_DIR = "static/images/members/"
WRITE_PATH = File.join SRC_PATH, STATIC_DIR
PLACEHOLDER = "https://unsplash.it/300/?random"
def download_and_save(name, url)
open(url) { |f|
file_path = File.join(WRITE_PATH, name)
File.open(file_path, "wb") do |file|
file.puts f.read
end
}
rescue
open(PLACEHOLDER) { |f|
file_path = File.join(WRITE_PATH, name)
File.open(file_path, "wb") do |file|
file.puts f.read
end
}
end
parsed = CSV.parse(File.open(CSV_FILE))
parsed.each do |member|
name = member[1]
image_url = member[4]
if name != 'name'
download_and_save(name, image_url)
end
end