Created
September 27, 2015 17:43
Tweet Harvest: Twitter User Data Dump-to-one-semi-clean-tweet-per-line file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
fo = File.open('/tmp/tweetstorm.txt','w') | |
Dir['./data/js/tweets/*.js'].each do |file| | |
begin | |
fh = File.open(file) | |
data = fh.read | |
# My Twitter dump had a first line that assigns the JSON data to a variable, | |
# the rest was valid JSON. Example: | |
# Grailbird.data.tweets_2009_07 = | |
json_data = JSON.parse(data.split("\n")[1..-1].join) | |
tweetz = json_data.map {|t| t['text'].gsub(/\@\w+/, '')} | |
tweetz.each {|t| fo.puts(t) } | |
ensure | |
fh.close | |
end | |
end | |
fo.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment