Wikipedia:Projekt DotNetWikiBot Framework/GameOnBot/Översättningsmallar
Utseende
using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Xml; using DotNetWikiBot; using System.Threading; class MyBot : Bot { public static void Main() { Site sitesvwp = new Site("http://sv.wikipedia.org", user, password); Site sitenowp; String tmpStr = ""; PageList pl = new PageList(sitesvwp); PageList pl2; Page myPage3; String orgStr; String article; String template; String url; int pos; int pos2; int end; PageList plList = new PageList(sitesvwp); plList.FillFromPageLinks("Användare:Grillo/permalänk"); foreach (Page myPageInList in plList) { article = myPageInList.title; Console.WriteLine(article); Thread.Sleep(5000); pl.Clear(); pl.FillFromPageHistoryEx(article, 50, true); DateTime dt, dt2; DateTime oldDt = new DateTime(); foreach (Page myPage in pl) { dt = myPage.timestamp; myPage.Load(); if(myPage.text.IndexOf("&oldid=") != -1) { Console.WriteLine("(Troligen) Redan fixad!"); break; } if(myPage.text.IndexOf("{{översatt") != -1) { tmpStr = myPage.text; oldDt = dt; } else { //We've found it Console.WriteLine(oldDt.ToString()); orgStr = tmpStr; pos = tmpStr.IndexOf("{{översatt"); if(pos == -1) pos = tmpStr.IndexOf("{{enwp"); if(pos == -1) pos = tmpStr.IndexOf("{{nowp"); if(pos == -1) { Console.WriteLine("Okänd mall!"); break; } pos2 = tmpStr.Substring(pos).IndexOf("url="); tmpStr = tmpStr.Substring(pos + pos2 + 4 + 29); end = tmpStr.IndexOf("|"); if(end == -1) end = tmpStr.IndexOf("}"); if(end == -1) { Console.WriteLine("Fel! Kan inte hitta slutet på url-sekvensen i anropet!"); break; } orgStr = orgStr.Substring(pos); tmpStr = tmpStr.Substring(0, end); end = orgStr.IndexOf("}"); orgStr = orgStr.Substring(0, end + 2); Console.WriteLine(orgStr); if(orgStr.IndexOf("no.wikipedia.org") != -1) { Console.WriteLine("Norska"); sitenowp = new Site("http://no.wikipedia.org", user, password); template = "nowp"; url = "no"; } else if(orgStr.IndexOf("en.wikipedia.org") != -1) { Console.WriteLine("Engelska"); sitenowp = new Site("http://en.wikipedia.org", user, password); template = "enwp"; url = "en"; } else { Console.WriteLine("Okänd!"); break; } pl2 = new PageList(sitenowp); pl2.FillFromPageHistoryEx(tmpStr, 50, true); foreach (Page myPage2 in pl2) { dt2 = myPage2.timestamp; if(dt2 < oldDt) { Console.WriteLine("dt2=" + dt2.ToString()); Console.WriteLine("revId=" + myPage2.lastRevisionID); myPageInList.Load(); myPageInList.text = myPageInList.text.Replace(orgStr, "{{" + template + "|url=http://" + url + ".wikipedia.org/w/index.php?title=" + tmpStr + "&oldid=" + myPage2.lastRevisionID + "}}"); myPageInList.Save(myPageInList.text, "Lägger in permalänk i översättningsmallen, ev. byter till respektive språks egna översättningsmall", true); break; } } break; } } } } }