Skip to content

Commit

Permalink
updating to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenn committed May 24, 2013
1 parent d7f1d63 commit a217621
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions twitter/twitterStatus.rb
Expand Up @@ -8,7 +8,8 @@
tweet_ids = Array.new tweet_ids = Array.new


#filename to save CSV #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"); filein = File.open("idsflisol2012.txt");


#saving ID's tweets #saving ID's tweets
Expand Down Expand Up @@ -36,33 +37,41 @@ def addquote(word)
save = ["id", "source" ]; save = ["id", "source" ];
save_user = ["screen_name", "location","followers_count", "friends_count", "listed_count", "time_zone","lang"] save_user = ["screen_name", "location","followers_count", "friends_count", "listed_count", "time_zone","lang"]


save_list = Array.new


#header CSV #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 #writing header in file
fileout.puts header fileout.write(header)


#search all id's info in twitter #search all id's info in twitter
tweet_ids.each do |val| tweet_ids.each do |val|
#fetch status #fetch status
begin begin
tweet = Twitter.status(val, {include_entities: "1"}) tweet = Twitter.status(val, {include_entities: "1"})
sleep(5) sleep(5)
#saving #saving
save.each do |val| save.each do |val|
save_list.push(addquote(tweet[val].to_s().gsub('\n', '').chomp)) save_list.push(addquote(tweet[val].to_s().gsub('\n', '').chomp))
end end


save_user.each do |val| 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 end


line = save_list.join(';') line = save_list.join(';')
fileout.puts line
line = line + "\n"

print line

fileout.write(line)

save_list.clear()
rescue Exception => msg rescue Exception => msg
puts "#{msg} id #{val}" puts "#{msg} id #{val}"


end end
end end
fileout.close();

0 comments on commit a217621

Please sign in to comment.