Created
April 11, 2018 20:33
-
-
Save jamjar919/9b6735c5c0d4fc4caf1d279da6472e18 to your computer and use it in GitHub Desktop.
Example MVE for facebook messenger counter
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 'nokogiri' | |
require 'axlsx' | |
catalog = ARGV[0] | |
user_name = Nokogiri::HTML(File.open("#{catalog}/index.htm")).title.split(' - Profile')[0] | |
friends = Hash.new | |
Dir.chdir("#{catalog}/messages") do | |
messages_files = Dir.glob("*.html") | |
messages_files.each do |file| | |
content = File.open(file).read | |
doc = Nokogiri::HTML(content) | |
friend_name = doc.title.split("Conversation with ")[1] | |
friends[friend_name] ||= 0 | |
puts "Analyzing conversation with: #{friend_name}" | |
conversation = doc.css('.message') | |
puts "Length #{conversation.length}" | |
conversation.each do |conversation_node| | |
if conversation_node['class'] == 'message' | |
friends[friend_name] += 1 | |
end | |
end | |
end | |
end | |
ranking = friends | |
package = Axlsx::Package.new | |
package.workbook.add_worksheet(name: "Friends ranking") do |sheet| | |
sheet.add_row ["Friends ranking"] | |
sheet.add_row ['ID', 'Friend name', 'total count'] | |
rank = 1 | |
ranking.each do |friend_name, friend_data| | |
sheet.add_row [rank, friend_name, | |
friend_data] | |
rank += 1 | |
end | |
end | |
package.serialize('facebook_messages.xlsx') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment