Last active
October 20, 2017 17:13
-
-
Save yetanotherchris/aabe1bb478b2a603adfddd4ba5f5355b to your computer and use it in GitHub Desktop.
WhatsApp message statistics. Needs LinqPad to run.
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
<Query Kind="Program"> | |
<Namespace>System.Globalization</Namespace> | |
</Query> | |
// Open a chat, click "..." and email to yourself (no media) | |
void Main() | |
{ | |
var messages = new List<Message>(); | |
string file = File.ReadAllText(@"/wapp.txt"); // c:\wapp.txt | |
string[] lines = file.Split('\n'); | |
for (int i = 0; i < lines.Length; i++) | |
{ | |
var parts = new List<string>(); | |
int dashIndex = lines[i].IndexOf(" - "); | |
if (dashIndex != -1) | |
{ | |
int colonIndex = lines[i].IndexOf(":", dashIndex); | |
if (colonIndex > -1) | |
{ | |
string date = lines[i].Substring(0, dashIndex); | |
string name = lines[i].Substring(dashIndex +3, colonIndex - (dashIndex +3)); | |
string text = lines[i].Substring(colonIndex +2, lines[i].Length - (colonIndex +2)); | |
var message = new Message() | |
{ | |
Date = DateTime.Parse(date), | |
Name = name, | |
Text = text | |
}; | |
messages.Add(message); | |
} | |
} | |
} | |
Console.WriteLine("{0} messages", messages.Count()); | |
// All days | |
var groupedBy = messages.GroupBy(x => x.Date.Date); | |
foreach (var item in groupedBy) | |
{ | |
//Console.WriteLine("{0}\t\t{1}", item.Key.ToString("dd ddd MMM"), item.Count()); | |
} | |
var groupedByDay = messages.GroupBy(x => x.Date.Date.Month); | |
foreach (var item in groupedByDay) | |
{ | |
Console.WriteLine("{0}-{1}", item.Key, item.Count()); | |
} | |
var groupedByHour = messages.GroupBy(x => x.Date.Hour); | |
foreach (var item in groupedByHour) | |
{ | |
//Console.WriteLine("{0}\t\t{1}", item.Key, item.Count()); | |
} | |
foreach (var item in messages.Where(x => x.Date.Date == DateTime.Now.Date)) | |
{ | |
//Console.WriteLine("{0}", item.Date.Hour); | |
} | |
} | |
public class Message | |
{ | |
public DateTime Date { get; set; } | |
public string Name { get; set; } | |
public string Text { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment