This is the code I’ve written to sum up the votes for the Muzik Market 2011 young artists competition.

The competition was in facebook here: https://www.facebook.com/NotJustMusic?sk=app_6009294086

here is a screen shot: 

The voters can play each one of the youtube videos, and than write in the comment box which young artist the vote for.

I needed to parse their comments, and could not used the facebook graph api, because the comments are really the deprecated FBML fb:comments.

So I used a little bit of C# ,LINQ and regex matching to get the votes.

I saved the html source in a file (that you can download with the full html from here:  http://db.tt/6FthoYs)

the code is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace NotJustMusic
{
public class MuzikMarketParser
{
private static IDictionary<long,string> mUsersMsgs = new Dictionary<long, string>();
public static void Main(string[] args)
{
int totalVotes = 0;
var s = File.ReadAllText(
“muzikmarket2011CodeBehind.txt”);

var m = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)\”>[^<]+</a><span class=\”wall_time\”>[^<]+</span></h4><div><span dir=\”rtl\”>([^<]+)”, RegexOptions.IgnoreCase | RegexOptions.Compiled);
AddVotesToDic(m, ref totalVotes);

m = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)\”>[^<]+</a><span class=\”wall_time\”>[^<]+</span></h4><div><br>([^<]+)”, RegexOptions.IgnoreCase | RegexOptions.Compiled);
AddVotesToDic(m, ref totalVotes);

m = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)\”>[^<]+</a><span class=\”wall_time\”>[^<]+</span></h4><div>([^<]+)”, RegexOptions.IgnoreCase | RegexOptions.Compiled);
AddVotesToDic(m, ref totalVotes);

m = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)\”><span dir=\”rtl\”>[^<]+</span></a><span class=\”wall_time\”>[^<]+</span></h4><div>([^<]+)”, RegexOptions.IgnoreCase | RegexOptions.Compiled);
AddVotesToDic(m, ref totalVotes);

m = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)\”><span dir=\”rtl\”>[^<]+</span></a><span class=\”wall_time\”>[^<]+</span></h4><div><span dir=\”rtl\”>([^<]+)”, RegexOptions.IgnoreCase | RegexOptions.Compiled);
AddVotesToDic(m, ref totalVotes);

var mNotMatched = Regex.Match(s, “<a href=\”http://www.facebook.com/profile.php\\?id=([\\d]+)”);

while (mNotMatched.Success)
{
var id = long.Parse(mNotMatched.Groups[1].ToString());
if (!mUsersMsgs.ContainsKey(id))
{
Console.Out.WriteLine(id);
}
mNotMatched = mNotMatched.NextMatch();
}

var theAssembly = mUsersMsgs.Values.Count(p => p.Contains(“אסמבלי”) || p.Contains(“assembly”) || (p.Contains(“שיר”) && p.Contains(“1”) && !p.Contains(“10”)));

var netaGalGal = mUsersMsgs.Values.Count(p => p.Contains(“neta”) || p.Contains(“gal”) || p.Contains(“נטע”) || p.Contains(“גל”) || (p.Contains(“שיר”) && p.Contains(“2”)));

var setler = mUsersMsgs.Values.Count(p => p.Contains(“סטלר”) || p.Contains(“סטאלר”) || p.Contains(“ליין”) || p.Contains(“stelar”) || p.Contains(“lane”) || (p.Contains(“שיר”) && p.Contains(“3”)));

var epicSign = mUsersMsgs.Values.Count(p => p.Contains(“epic”) || p.Contains(“sign”) || (p.Contains(“שיר”) && p.Contains(“4”)));

var asaf = mUsersMsgs.Values.Count(p => p.Contains(“assaf”) || p.Contains(“asaf”) || p.Contains(“אסף”) || p.Contains(“פייביש”) || p.Contains(“פיביש”) || (p.Contains(“שיר”) && p.Contains(“5”)));

var hofitDror = mUsersMsgs.Values.Count(p => p.Contains(“dror”) || p.Contains(“hofit”) || p.Contains(“חופית”) || p.Contains(“דרור”) || (p.Contains(“שיר”) && p.Contains(“6”)));

var daniel = mUsersMsgs.Values.Count(p => p.Contains(“daniel”) || p.Contains(“דניאל”) || (p.Contains(“שיר”) && p.Contains(“7”)));

var moish = mUsersMsgs.Values.Count(p => p.Contains(“dokler”) || p.Contains(“moysh”) || p.Contains(“מויש”) || p.Contains(“מויש”) || p.Contains(“דוקלר”) || p.Contains(“דקלר”) || (p.Contains(“שיר”) && p.Contains(“8”)));

var omer = mUsersMsgs.Values.Count(p => p.Contains(“עומר”) || p.Contains(“סולודוך”) || p.Contains(“סולדוך”) || p.Contains(“omer”) || (p.Contains(“שיר”) && p.Contains(“9”)));

var benia = mUsersMsgs.Values.Count(p => p.Contains(“בניה”) || p.Contains(“בנייה”) || p.Contains(“ברבי”) || p.Contains(“barbi”) || p.Contains(“benia”) || p.Contains(“ב נ י ה”) || (p.Contains(“שיר”) && p.Contains(“10”)));

Console.Out.WriteLine(“theAssembly: ” + theAssembly);
Console.Out.WriteLine(“netaGalGal: ” + netaGalGal);
Console.Out.WriteLine(“setler: ” + setler);
Console.Out.WriteLine(“epicSign: ” + epicSign);
Console.Out.WriteLine(“asaf: ” + asaf);
Console.Out.WriteLine(“hofitDror: ” + hofitDror);
Console.Out.WriteLine(“daniel: ” + daniel);
Console.Out.WriteLine(“moish: ” + moish);
Console.Out.WriteLine(“omer: ” + omer);
Console.Out.WriteLine(“benia: ” + benia);

Console.Out.WriteLine(“Total Votes: ” + totalVotes);

Console.Out.WriteLine(“Total Unique Votes: ” + mUsersMsgs.Keys.Count);

Console.Out.WriteLine(“Total Unique Legal Votes: ” +(int)( theAssembly + netaGalGal + setler + epicSign + asaf + hofitDror + daniel + moish + omer + benia));

}

private static void AddVotesToDic(Match m, ref int totalVotes)
{
while(m.Success)
{
totalVotes++;
var id = long.Parse(m.Groups[1].ToString());
var msg = m.Groups[2].ToString();
if (!mUsersMsgs.ContainsKey(id))
{
mUsersMsgs.Add(id, msg.ToLower());
}
m = m.NextMatch();
}
}
}
}

the output is:

theAssembly: 4
netaGalGal: 2
setler: 179
epicSign: 9
asaf: 174
hofitDror: 10
daniel: 42
moish: 150
omer: 1070
benia: 1018
Total Votes: 2844
Total Unique Votes: 2675
Total Unique Legal Votes: 2658

So the winner with 1070 votes is the young artist

Omer Solodoch!

Advertisements