mirror of
https://github.com/thewesker/twitter_ebooks.git
synced 2025-12-23 05:41:08 -05:00
Merge pull request #20 from BooDoo/feature/jsonify-csv
jsonify: Support tweets.csv
This commit is contained in:
26
bin/ebooks
26
bin/ebooks
@@ -2,6 +2,7 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require 'twitter_ebooks'
|
require 'twitter_ebooks'
|
||||||
|
require 'csv'
|
||||||
|
|
||||||
$debug = true
|
$debug = true
|
||||||
|
|
||||||
@@ -154,16 +155,23 @@ STR
|
|||||||
|
|
||||||
tweets = []
|
tweets = []
|
||||||
id = nil
|
id = nil
|
||||||
File.read(path).split("\n").each do |l|
|
if path.split('.')[-1] == "csv" #from twitter archive
|
||||||
if l.start_with?('# ')
|
csv_archive = CSV.read(path, :headers=>:first_row)
|
||||||
id = l.split('# ')[-1]
|
tweets = csv_archive.map do |tweet|
|
||||||
else
|
{ text: tweet['text'], id: tweet['tweet_id'] }
|
||||||
tweet = { text: l }
|
end
|
||||||
if id
|
else
|
||||||
tweet[:id] = id
|
File.read(path).split("\n").each do |l|
|
||||||
id = nil
|
if l.start_with?('# ')
|
||||||
|
id = l.split('# ')[-1]
|
||||||
|
else
|
||||||
|
tweet = { text: l }
|
||||||
|
if id
|
||||||
|
tweet[:id] = id
|
||||||
|
id = nil
|
||||||
|
end
|
||||||
|
tweets << tweet
|
||||||
end
|
end
|
||||||
tweets << tweet
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user