-
Notifications
You must be signed in to change notification settings - Fork 1
/
ext-library-list.rb
executable file
·59 lines (54 loc) · 1.37 KB
/
ext-library-list.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
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$:.push( File.dirname($0) )
require "local_government.rb"
require "rubygems"
require "libxml"
if $0 == __FILE__
parser = LibXML::XML::Parser.io( ARGF )
doc = parser.parse
#puts Time.now - time
doc.root.namespaces.default_prefix = 'mw'
pages = doc.find( "//mw:page" )
pages.each do |page|
title = page.find( "./mw:title" )[0].content
text = page.find( "./mw:revision/mw:text" )[0].content
pref = nil
if text == "ここに本文が入ります。"
PREF.each do |k, v|
if title.include? v
pref = v
break
end
end
if not pref
LOCAL.each do |k, v|
next if v.empty?
#p [ k, v ]
if title.start_with? v
pref = PREF[ k[ 0, 2 ].to_i ]
#puts [ title, v ].join( "\t" )
break
end
end
end
cat = "[[Category:公共図書館]]"
if pref.nil?
pref = "○○県"
cat = nil
end
#puts [ title, pref, cat ].join( "\t" )
open( "#{ title }.txt", "w" ) do |io|
io.print <<EOF
{{subst:新規施設
| 名称=#{ title }
| よみ=
| 都道府県=#{ pref }
| 施設種別=図書館
}}
#{ cat }
EOF
end
end
end
end