Hoppa till innehållet

Wikipedia:Projekt DotNetWikiBot Framework/Innocent bot/Sidantal på Wikisource

Från Wikipedia
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Xml;
using System.Threading;
using DotNetWikiBot;

class MyBot : Bot
{
	public static void Main()
	{
		string mall = "{{#switch:{{{1|0}}}\n|0=$0$\n|1=$1$\n|2=$2$\n|3=$3$\n|4=$4$\n|5=$5$\n|6=$6$\n|7=$7$\n|8=$8$\n|9=$9$\n|10=$10$\n|11=$11$\n|12=$12$\n|13=$13$\n|14=$14$\n|15=$15$\n|90=$90$\n|91=$91$\n|92=$92$\n|93=$93$\n|104=$104$\n|105=$105$\n|106=$106$\n|107=$107$\n|108=$108$\n|109=$109$\n|828=$828$\n|829=$829$\n}}<noinclude>\n{{/dok}}\n</noinclude>";
		string[] ns = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","90","91","92","93","104","105","106","107","108","109","828","829"};
		Site site = new Site("http://sv.wikisource.org", "********", "********");
		PageList pl = new PageList(site);
		Page p = new Page(site, "Mall:Antalsidor");
		p.Load();
		foreach(string n in ns)
		{
				string next = "";
				int tot = 0;
				while(next != "Happy ending")
				{
					string urlstr = "http://sv.wikisource.org/w/api.php?action=query&apfilterredir=nonredirects&list=allpages&aplimit=5000&apnamespace="+n+"&apcontinue="+next;
					string material = site.GetPageHTM(urlstr);
					int s = material.Length;
					material = material.Replace("<p pageid=&quot","<ppageid=&quot");
					s = s-material.Length;
					tot = tot+s;
					if(material.IndexOf("apcontinue="") != -1)
					{
						material = material.Substring(material.IndexOf("apcontinue="")+17);
						next = material.Substring(0,material.IndexOf("" />"));
					}
					else
						next = "Happy ending";
				}
				mall = mall.Replace("$"+n+"$", tot.ToString());
		}
		p.text=mall;
		Bot.editComment = "Uppdaterar mall";
		isMinorEdit = false;
		//Console.WriteLine(p.text);
		p.Save();
		
	}
}