-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrollup.rb
36 lines (32 loc) · 880 Bytes
/
rollup.rb
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
# rollup per-page lists to per-site and per-scrape lists
# Index ► Ruby:rollup ► read Pages:words.txt
# Index ► Ruby:rollup ► read Pages:sites.txt
# Index ► Ruby:rollup ► write Sites:words.txt ► write Search:words.txt
# Index ► Ruby:rollup ► write Sites:sites.txt ► write Search:sites.txt
def rollup path, part, file
hash = {}
Dir.glob("#{path}/#{part}/#{file}") do |filename|
File.open(filename, 'r').each do |line|
hash[line] = true
end
end
if hash.empty?
File.delete("#{path}/#{file}") if File.exist?("#{path}/#{file}")
else
File.open("#{path}/#{file}", 'w') do |file|
file.puts hash.keys.sort
end
end
end
def sites file
puts file
Dir.glob("sites/*") do |dirname|
rollup dirname, 'pages/*/', file
end
rollup '.', 'sites/*', file
end
sites 'links.txt'
sites 'sites.txt'
sites 'words.txt'
sites 'items.txt'
sites 'plugins.txt'