-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmokuroku.rb
70 lines (65 loc) · 1.87 KB
/
mokuroku.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'digest/md5'
require 'open-uri'
require 'json'
DRY_RUN = false
APPENDING = false
$src_dir = '/var/www/htdocs/xyz'
$tes = []
def process(entry, stack)
case entry['type']
when 'LayerGroup'
stack.push(entry['title'])
entry['entries'].each {|child|
process(child, stack)
}
stack.pop
when 'Layer'
stack.push(entry['title'])
r = entry['url'].split('/{z}/{x}/{y}.')
if r.size == 2
$tes << [r[0].split('/xyz/')[-1], r[1]]
end
stack.pop
end
end
[0, 1, 2, 3, 4, '_experimental', '_invisible'].each {|e|
url = "http://gsi-cyberjapan.github.io/gsimaps/layers_txt/layers#{e}.txt"
JSON.parse(open(url).read)['layers'].each {|entry|
process(entry, [])
}
}
$tes.uniq!
$tes.each {|t, e|
dst_path = "/var/www/htdocs/xyz/#{t}/mokuroku.csv"
next if File.exist?(dst_path + ".gz") if APPENDING
print "Creating #{dst_path}\n" if DRY_RUN
w = DRY_RUN ? $stdout : File.open(dst_path, 'w')
zs = Dir.entries("#{$src_dir}/#{t}").
sort{|a, b| a.to_i <=> b.to_i}.
select{|v| v.to_i.to_s == v}
zs.each {|z|
xs = Dir.entries("#{$src_dir}/#{t}/#{z}").
sort{|a, b| b.to_i <=> a.to_i}.
select{|v| v.to_i.to_s == v}
xs.each {|x|
ys = Dir.entries("#{$src_dir}/#{t}/#{z}/#{x}").
map{|v| v.split('.')[0]}.
sort{|a, b| a.to_i <=> b.to_i}.
select{|v| v.to_i.to_s == v}.uniq
sleep 10 if File.exist?('sleep')
ys.each {|y|
path = "#{$src_dir}/#{t}/#{z}/#{x}/#{y}.#{e}"
# print ["#{z}/#{x}/#{y}", "#{t}/#{z}/#{x}/#{y}.#{e}"].join("\t"), "\n"
begin
w.print ["#{z}/#{x}/#{y}.#{e}",
File.mtime(path).to_i, File.size(path),
Digest::MD5.file(path)].join(','), "\n"
rescue
# file not found, maybe deleted.
end
}
}
}
w.close unless DRY_RUN
system "gzip -9f /var/www/htdocs/xyz/#{t}/mokuroku.csv" unless DRY_RUN
}