From 74fd9c1e2e236ac28ad69045592b6487c4fcb913 Mon Sep 17 00:00:00 2001 From: Joel McCoy Date: Tue, 27 May 2014 19:14:19 -0400 Subject: [PATCH] jsonify: Support tweets.csv Allow official archive tweets.csv as input to create Ebooks::Archive compatible JSON archive --- bin/ebooks | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/ebooks b/bin/ebooks index cd169ec..e1dbbad 100755 --- a/bin/ebooks +++ b/bin/ebooks @@ -2,6 +2,7 @@ # encoding: utf-8 require 'twitter_ebooks' +require 'csv' $debug = true @@ -154,16 +155,23 @@ STR 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