Created
September 25, 2015 17:22
-
-
Save EgorBo/f50a27712fc14f6d6717 to your computer and use it in GitHub Desktop.
Top jabber.ru (dotnet conf) flooders
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using HtmlAgilityPack; | |
namespace ConsoleApplication16 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const int topLimit = 40; | |
List<string> nicks = new List<string>(100000); | |
for (int year = 2008; year <= 2015; year++) | |
{ | |
for (int month = (year == 2008 ? 7 : 1); month <= 12; month++) | |
{ | |
for (int day = 1; day <= 31; day++) //Parallel.For ? | |
{ | |
nicks.AddRange(GetFloodersForGivenDay(year, month, day)); | |
} | |
} | |
} | |
Console.Clear(); | |
var topFlooders = nicks.GroupBy(g => g).Select(i => new { Nick = i.Key, Msgs = i.Count() }).OrderByDescending(i => i.Msgs).Take(topLimit).ToArray(); | |
for (int place = 0; place < topFlooders.Length; place++) | |
{ | |
var flooder = topFlooders[place]; | |
Console.WriteLine($"{place}. {flooder.Nick} - ({flooder.Msgs} messages)"); | |
} | |
Console.ReadKey(); | |
} | |
static IEnumerable<string> GetFloodersForGivenDay(int year, int month, int day) | |
{ | |
try | |
{ | |
HtmlDocument docHtml = new HtmlWeb().Load($"http://chatlogs.jabber.ru/[email protected]/{year}/{month.ToString("00")}/{day.ToString("00")}.html"); | |
return docHtml.DocumentNode.SelectNodes("//font[@class='mn']").Select(n => n.InnerText.Replace("<", "").Replace(">", "")).ToArray(); | |
} | |
catch (Exception exc) | |
{ | |
Console.WriteLine($"Fail for date: {day}.{month}.{year}"); | |
//404? | |
return new string[0]; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment