Wikipedia:Projekt DotNetWikiBot Framework/Innocent bot/Patrullering
Utseende
using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Threading; using System.Web; using System.Net; using System.Drawing; using System.Windows.Forms; using DotNetWikiBot; class MyBot : Bot { public static void Vitlistan() { Site site = new Site("http://sv.wikipedia.org", "********", "********"); Page p = new Page(site, "Användare:Innocent bot/Patrulleringar"); p.Load(); List<string> vitalistan = new List<string> (); string whiteanvändare = ""; string user = ""; string rcid = ""; string patroltoken = ""; string title = ""; XmlTextReader reader; List<int> namespaces = new List<int>{0, 1, 2, 3, 4, 5, 9, 10, 11, 14, 15, 100, 101, 828, 829}; string whitelist = site.GetPageHTM("http://sv.wikipedia.org/wiki/Användare:Patrullroboten/Whitelist"); int i; int i2; string tmpStr; whitelist = whitelist.Substring(whitelist.IndexOf("<!-- bodycontent -->") + 20); File.WriteAllText("whitelist.txt", whitelist); while(whitelist.IndexOf("title=\"Användare:") != -1) { whitelist = whitelist.Substring(whitelist.IndexOf("title=\"Användare:")+7); whiteanvändare = whitelist.Substring(0, whitelist.IndexOf("\"")); whiteanvändare = whiteanvändare.Replace(" [inte skriven än]", ""); whiteanvändare = whiteanvändare.Replace("Användare:", ""); vitalistan.Add(whiteanvändare.Trim()); } string aaa = ""; for(i2 = 0; i2 < namespaces.Count; i2++) { tmpStr = site.PostDataAndGetResultHTM("http://sv.wikipedia.org/w/api.php", "action=query&list=recentchanges&format=xml&rcprop=user|title|ids&rcshow=!patrolled&rctoken=patrol&rctype=new&rclimit=5000&rcnamespace=" + namespaces[i2].ToString()); System.IO.File.WriteAllText("rc" + namespaces[i2].ToString() + ".xml", tmpStr); for(i = 0; i < vitalistan.Count; i++) { if(vitalistan[i].Length > 0) { reader = new XmlTextReader ("rc" + namespaces[i2].ToString() + ".xml"); while(reader.Read()) { switch(reader.NodeType) { case XmlNodeType.Element : if(reader.Name == "rc") { user = reader.GetAttribute("user"); if(user == vitalistan[i]) { rcid = reader.GetAttribute("rcid"); //Behövs bara en gång, jämför med rad 88-89 i api\includes\ApiQueryRecentChanges för 1.18, dock måste den omkodas lite (i enlighet med mediawiki:API) if(patroltoken == "") patroltoken = reader.GetAttribute("patroltoken").Replace("+", "%2B"); title = reader.GetAttribute("title"); site.PostDataAndGetResultHTM("http://sv.wikipedia.org/w/api.php", "action=patrol&token=" + patroltoken + "&rcid=" + rcid+"&format=xml"); Console.WriteLine(user); if(p.text.IndexOf(user) != -1) { int a = p.text.IndexOf(user); a = p.text.IndexOf("||", a)+2; int b = p.text.IndexOf("\n", a); int c = int.Parse(p.text.Substring(a, b-a).Trim()); c += 1; p.text = p.text.Substring(0,a)+" "+c.ToString()+p.text.Substring(b); } else { p.text = p.text.Replace("<!-- $$$ -->", "|-\n| "+user+" || 1\n<!-- $$$ -->"); } } } else if(reader.Name == "recentchanges") { aaa = reader.GetAttribute("rcstart"); } break; } } reader.Close(); } } } Bot.editComment = "Statistik för patrulleringar"; isMinorEdit = true; p.Save(); } public static void Andra() { Site site = new Site("http://sv.wikipedia.org", "*********", "********"); List<int> namespaces = new List<int>{2, 3}; string aaa = ""; XmlTextReader reader; string rcid = ""; string user = ""; string patroltoken = ""; string title = ""; for(int i2 = 0; i2 < namespaces.Count; i2++) { string tmpStr = site.PostDataAndGetResultHTM("http://sv.wikipedia.org/w/api.php", "action=query&list=recentchanges&format=xml&rcprop=user|title|ids&rcshow=!patrolled&rctoken=patrol&rctype=new&rclimit=5000&rcnamespace=" + namespaces[i2].ToString()); System.IO.File.WriteAllText("rc" + namespaces[i2].ToString() + ".xml", tmpStr); reader = new XmlTextReader ("rc" + namespaces[i2].ToString() + ".xml"); while(reader.Read()) { switch(reader.NodeType) { case XmlNodeType.Element : if(reader.Name == "rc") { user = reader.GetAttribute("user"); if(char.IsLetter(user[0])) { rcid = reader.GetAttribute("rcid"); //Behövs bara en gång, jämför med rad 88-89 i api\includes\ApiQueryRecentChanges för 1.18, dock måste den omkodas lite (i enlighet med mediawiki:API) if(patroltoken == "") patroltoken = reader.GetAttribute("patroltoken").Replace("+", "%2B"); title = reader.GetAttribute("title"); site.PostDataAndGetResultHTM("http://sv.wikipedia.org/w/api.php", "action=patrol&token=" + patroltoken + "&rcid=" + rcid); Console.WriteLine(user); Bot.Wait(10); } } else if(reader.Name == "recentchanges") { aaa = reader.GetAttribute("rcstart"); } break; } } reader.Close(); } } public static void Main() { Vitlistan(); Andra(); } }