bin/ebooks in twitter_ebooks-2.1.3 vs bin/ebooks in twitter_ebooks-2.1.4

- old
+ new

@@ -36,14 +36,13 @@ pathes.each do |path| filename = File.basename(path) shortname = filename.split('.')[0..-2].join('.') hash = Digest::MD5.hexdigest(File.read(path)) - log "Consuming text corpus: #{filename}" outpath = File.join(APP_PATH, 'model', "#{shortname}.model") Model.consume(path).save(outpath) - log "Corpus consumed" + log "Corpus consumed to #{outpath}" end end def self.gen(model_path, input) model = Model.load(model_path) @@ -71,32 +70,34 @@ bot = Bot.get(username) bot.configure bot.tweet(statement) end - def self.jsonify(old_path, new_path) - name = File.basename(old_path).split('.')[0] - new_path ||= name + ".json" + def self.jsonify(paths) + paths.each do |path| + name = File.basename(path).split('.')[0] + new_path = name + ".json" - tweets = [] - id = nil - File.read(old_path).split("\n").each do |l| - if l.start_with?('# ') - id = l.split('# ')[-1] - else - tweet = { text: l } - if id - tweet[:id] = id - id = nil + tweets = [] + id = nil + File.read(path).split("\n").each do |l| + if l.start_with?('# ') + id = l.split('# ')[-1] + else + tweet = { text: l } + if id + tweet[:id] = id + id = nil + end + tweets << tweet end - tweets << tweet end - end - File.open(new_path, 'w') do |f| - log "Writing #{tweets.length} tweets to #{new_path}" - f.write(JSON.pretty_generate(tweets)) + File.open(new_path, 'w') do |f| + log "Writing #{tweets.length} tweets to #{new_path}" + f.write(JSON.pretty_generate(tweets)) + end end end def self.command(args) usage = """Usage: @@ -104,11 +105,11 @@ ebooks consume <corpus_path> [...] ebooks gen <model_path> [input] ebooks score <model_path> <input> ebooks archive <@user> <outpath> ebooks tweet <model_path> <@bot> - ebooks jsonify <old_corpus_path> [new_corpus_path] + ebooks jsonify <old_corpus_path> [...] """ if args.length == 0 log usage exit @@ -119,10 +120,10 @@ when "consume" then consume(args[1..-1]) when "gen" then gen(args[1], args[2..-1].join(' ')) when "score" then score(args[1], args[2..-1].join(' ')) when "archive" then archive(args[1], args[2]) when "tweet" then tweet(args[1], args[2]) - when "jsonify" then jsonify(args[1], args[2]) + when "jsonify" then jsonify(args[1..-1]) end end end Ebooks.command(ARGV)