-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
crawlthings.rb
38 lines (32 loc) · 1.19 KB
/
crawlthings.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
# Crawl repositories under a base directory and find things in ESH-INF/thing directories
# TODO: doesn't handle translated labels and descriptions...
require "nokogiri"
require "json"
if (!ARGV[0])
puts "Usage: crawlthings.rb rootPath"
puts "Put smarthome, openhab2-addons, org.openhab.binding.zigbee, org.openhab.binding.zwave repos under rootPath"
exit(1)
end
$rootDir = ARGV[0] + File::SEPARATOR
$things = []
puts "Crawling #{$rootDir}"
$i = 0
Dir.glob($rootDir + "/**/ESH-INF/thing/**/*.xml").each { |file|
if !(file =~ /test/) then
xml = Nokogiri::XML(open(file))
bindingId = xml.xpath("//@bindingId").text
xml.xpath("//bridge-type|//thing-type").each { |t|
thing = {
"id" => "#{bindingId}:#{t["id"]}",
"label" => t.xpath("label").text,
# "description" => t.xpath("description").text,
"bindingId" => bindingId
}
$things.push(thing) if thing["id"] != "sample"
}
end
}
File.open(".vuepress/components/things/things.json", "w+") { |f|
f.write(JSON.pretty_generate($things))
}
puts "#{$things.size} things written to .vuepress/components/things/things.json"