using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Web;
using System.Threading;
using DotNetWikiBot;
class MyBot : Bot
{
public static List<string> OwnFillFromLinksToPage(Site site, string pageTitle)
{
List<string> r = new List<string>();
if (string.IsNullOrEmpty(pageTitle))
throw new ArgumentNullException("pageTitle");
//RemoveAll();
string res = site.site + site.indexPath +
"index.php?title=Special:Whatlinkshere/" +
HttpUtility.UrlEncode(pageTitle) + "&limit=5000&hidelinks=1&namespace=0";
do
{
string src = site.GetPageHTM(res);
if(src.IndexOf(">nästa 5 000<") != -1)
{
int s = src.IndexOf(">nästa 5 000<");
s = src.LastIndexOf("<a href=\"", s)+9;
int s1 = src.IndexOf("\" title=", s)-s;
res = site.site + src.Substring(s, s1);
res = res.Replace("&", "&");
}
else
res = "";
Console.WriteLine(res);
MatchCollection matches = Site.linkToPageRE1.Matches(src);
foreach (Match match in matches)
r.Add(HttpUtility.HtmlDecode(match.Groups[1].Value));
}while(res != "");
//RemoveRedirects();
Console.WriteLine(
Bot.Msg("PageList filled with titles of pages, referring to \"{0}\" page."),
pageTitle);
return r;
}
public static void Main()
{
Site site = new Site("http://sv.wikipedia.org", "Innocent bot", "********");
Site site2 = new Site("http://commons.wikimedia.org", "Innocent bot", "********");
List<string> sidor = new List<string>();
List<string> mallade = new List<string>();
sidor = OwnFillFromLinksToPage(site, "Mall:Kommunfakta Frankrike");
mallade = OwnFillFromLinksToPage(site, "Mall:Franska kommunkartor");
Console.WriteLine(sidor.Count);
Console.WriteLine(mallade.Count);
sidor.Sort();
foreach(string kommun in sidor)
{
if(!mallade.Contains(kommun))
{
Page p = new Page(site, kommun);
p.Load();
string insee = p.GetTemplateParameter("Kommunfakta Frankrike", "insee")[0];
string fil = "File:Map commune FR insee code "+insee+".png";
Page pc = new Page(site2, fil);
pc.Load();
if(pc.Exists())
{
string[] mallar;
mallar = p.GetTemplatesWithParams();
foreach(string mall in mallar)
{
if(mall.StartsWith("Kommunfakta Frankrike"))
{
int s = p.text.IndexOf(mall)+mall.Length;
s = p.text.IndexOf("}}", s)+2;
p.text = p.text.Substring(0,s)+"\n{{Franska kommunkartor|"+insee+"}}"+p.text.Substring(s);
p.Save(p.text, "Lägger in fransk kommunkarta", true);
Bot.Wait(10000);
break;
}
}
}
}
}
}
}