-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare.rb
41 lines (35 loc) · 1.12 KB
/
prepare.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
libdir = File.expand_path(File.join(File.dirname(__FILE__), 'lib/'))
srcdir = File.expand_path(File.join(File.dirname(__FILE__), 'src/'))
$LOAD_PATH.unshift(srcdir) unless $LOAD_PATH.include?(srcdir)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require 'yaml'
require 'json'
require 'confstruct'
require 'feed_parser'
require 'xml_parser'
require 'debugger'
# which collection are we processing? Make sure one was provided.
collection = ARGV[0]
if (collection.nil?)
puts "Please pass a collection name to process. Available collections are in the config.yaml file."
exit;
end
# get our configuration data
config = Confstruct::Configuration.new(
YAML.load_file(
File.expand_path(
File.join(File.dirname(__FILE__), 'config.yaml')
)
)
)
# iterate over all the files, and convert them to the json format.
files_to_convert = Dir[File.expand_path(File.join(File.dirname(__FILE__),
config.data.path,
collection,
config.collections[collection].path))
]
files_to_convert.each do |feed_path|
feed = File.open(feed_path, 'r').read
gb = Parsers::XMLParser.new(feed, collection, config)
gb.process
end