2.1.3 - better archiver

This commit is contained in:
Mispy 2013-11-24 13:16:34 -08:00
parent c3053e5091
commit acc2f42b38
7 changed files with 124 additions and 90 deletions

View file

@ -60,7 +60,7 @@ module Ebooks
end
def self.archive(username, outpath)
Archiver.new(username, outpath).fetch_tweets
Archive.new(username, outpath).sync
end
def self.tweet(modelpath, username)
@ -73,6 +73,31 @@ module Ebooks
bot.tweet(statement)
end
def self.jsonify(old_path, new_path)
name = File.basename(old_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
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))
end
end
def self.command(args)
usage = """Usage:
ebooks new <reponame>
@ -81,6 +106,7 @@ module Ebooks
ebooks score <model_path> <input>
ebooks archive <@user> <outpath>
ebooks tweet <model_path> <@bot>
ebooks jsonify <old_corpus_path> [new_corpus_path]
"""
if args.length == 0
@ -95,6 +121,7 @@ module Ebooks
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])
end
end
end