jsonify: Support tweets.csv
Allow official archive tweets.csv as input to create Ebooks::Archive compatible JSON archive
This commit is contained in:
parent
db453600be
commit
74fd9c1e2e
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