Merge pull request #20 from BooDoo/feature/jsonify-csv
jsonify: Support tweets.csv
This commit is contained in:
commit
4b88d3326b
1 changed files with 17 additions and 9 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require 'twitter_ebooks'
|
require 'twitter_ebooks'
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
$debug = true
|
$debug = true
|
||||||
|
|
||||||
|
|
@ -154,6 +155,12 @@ STR
|
||||||
|
|
||||||
tweets = []
|
tweets = []
|
||||||
id = nil
|
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|
|
File.read(path).split("\n").each do |l|
|
||||||
if l.start_with?('# ')
|
if l.start_with?('# ')
|
||||||
id = l.split('# ')[-1]
|
id = l.split('# ')[-1]
|
||||||
|
|
@ -166,6 +173,7 @@ STR
|
||||||
tweets << tweet
|
tweets << tweet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
File.open(new_path, 'w') do |f|
|
File.open(new_path, 'w') do |f|
|
||||||
log "Writing #{tweets.length} tweets to #{new_path}"
|
log "Writing #{tweets.length} tweets to #{new_path}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue