google_hangouts_parser.rb (902B)
1 #!/usr/bin/env ruby 2 # Parses a Hangouts.json file downloaded from Google Hangouts 3 require 'json' 4 File.open("Hangouts.json") do |f| 5 t=JSON.parse(f.read) 6 t["conversations"].each do |conv| 7 sender_1 = { name: conv["conversation"]["conversation"]["participant_data"].first["fallback_name"], id: conv["conversation"]["conversation"]["participant_data"].first["id"] } 8 sender_2 = { name: conv["conversation"]["conversation"]["participant_data"][1]["fallback_name"], id: conv["conversation"]["conversation"]["participant_data"][1]["id"] } 9 puts "#{sender_1[:name]} & #{sender_2[:name]}" 10 conv['events'].each do |evt| 11 evt['chat_message']['message_content']['segment'].each do |seg| 12 print "#{(sender_1[:id] == evt['sender_id'] ? sender_1[:name].split.first : sender_2[:name].split.first)}: " 13 puts seg['text'] 14 end 15 end 16 10.times { print "#" } 17 puts 18 end 19 end