Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created September 25, 2015 17:22
Show Gist options
  • Save EgorBo/f50a27712fc14f6d6717 to your computer and use it in GitHub Desktop.
Save EgorBo/f50a27712fc14f6d6717 to your computer and use it in GitHub Desktop.
Top jabber.ru (dotnet conf) flooders
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("&lt;", "").Replace("&gt;", "")).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