bin/ebooks in twitter_ebooks-2.2.5 vs bin/ebooks in twitter_ebooks-2.2.6
- old
+ new
@@ -1,9 +1,10 @@
#!/usr/bin/env ruby
# encoding: utf-8
require 'twitter_ebooks'
+require 'csv'
$debug = true
module Ebooks
APP_PATH = Dir.pwd # XXX do some recursive thing instead
@@ -114,13 +115,14 @@
Archive.new(username, outpath).sync
end
def self.tweet(modelpath, botname)
usage = <<STR
-Usage: ebooks jsonify <old_corpus_path> [old_corpus_path2] [...]
+Usage: ebooks tweet <model_path> <botname>
-Takes an old-style corpus of plain tweet text and converts it to json.
+Sends a public tweet from the specified bot using text
+from the processed model at <model_path>.
STR
if modelpath.nil? || botname.nil?
log usage
exit
@@ -151,19 +153,26 @@
name = File.basename(path).split('.')[0]
new_path = name + ".json"
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
+ if path.split('.')[-1] == "csv" #from twitter archive
+ csv_archive = CSV.read(path, :headers=>:first_row)
+ tweets = csv_archive.map do |tweet|
+ { text: tweet['text'], id: tweet['tweet_id'] }
+ end
+ else
+ 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}"