User:MiniBot/Code/PoliticalCleanup

From eRepublik Official Wiki
Jump to: navigation, search

I, the author, release this code as public domain.

Page p=new Page(site,"Special:Whatlinkshere/Template:Politicalinfobox");
p.Load();
if(p.Exists())
        Console.WriteLine(">Page found");
Regex reg=new Regex("<li>.+?\">(.+?)</a>.\\(inclusion\\)");
List<string> parties=new List<string>();
foreach(Match a in reg.Matches(p.text)){
        Console.Write(a.Groups[1].Value+",");
        parties.Add(HttpUtility.HtmlDecode(a.Groups[1].Value));
}
Console.WriteLine("");
string[] arr = parties.ToArray();

PageList pl = new PageList(site, arr);
Console.WriteLine(">List prepared");

pl.Load();
Console.WriteLine(">Pages loaded");		
parties.Clear();
Regex wrong=new Regex("\\[\\[$");
foreach(Page page in pl){
    if(page.Exists()){
            if(wrong.Match(page.text).Length>0){
                Match m=wrong.Match(page.text);
                Console.WriteLine(">Page "+page.title+" has match:"+m.Value+".");
                page.text=wrong.Replace(page.text,"");
                page.Save();
            }
    }
    else
        Console.WriteLine(">Page ["+page.title+"] does not exist,");
}