From a217621d1c9858f6519c438472f6a49ba27d4eaa Mon Sep 17 00:00:00 2001 From: Jenn Date: Fri, 24 May 2013 17:19:27 -0300 Subject: [PATCH] updating to file --- twitter/twitterStatus.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/twitter/twitterStatus.rb b/twitter/twitterStatus.rb index f9cd914..98a8ca0 100644 --- a/twitter/twitterStatus.rb +++ b/twitter/twitterStatus.rb @@ -8,7 +8,8 @@ tweet_ids = Array.new #filename to save CSV -fileout = File.new("twitter_flisol2011-2012.csv", "w") +fileout = File.open("twitter_flisol2011-2012.csv", "w") + filein = File.open("idsflisol2012.txt"); #saving ID's tweets @@ -36,13 +37,13 @@ def addquote(word) save = ["id", "source" ]; save_user = ["screen_name", "location","followers_count", "friends_count", "listed_count", "time_zone","lang"] -save_list = Array.new #header CSV -header = 'id; text; source; screen_name; location; followers_count; friends_count; listed_count; time_zone; lang' +header = 'id; source; screen_name; location; followers_count; friends_count; listed_count; time_zone; lang' +save_list = Array.new #writing header in file -fileout.puts header +fileout.write(header) #search all id's info in twitter tweet_ids.each do |val| @@ -50,19 +51,27 @@ def addquote(word) begin tweet = Twitter.status(val, {include_entities: "1"}) sleep(5) - #saving + #saving save.each do |val| save_list.push(addquote(tweet[val].to_s().gsub('\n', '').chomp)) end save_user.each do |val| - save_list.push(addquote(tweet["user"][val].to_s().gsub('\n', ''))) + save_list.push(addquote(tweet["user"][val].to_s().gsub('\n', '').chomp)) end line = save_list.join(';') - fileout.puts line + + line = line + "\n" + + print line + + fileout.write(line) + + save_list.clear() rescue Exception => msg puts "#{msg} id #{val}" end end +fileout.close();