//Code for extracting all pages in a category that lacks {{defaultsort}} or {{standardsortering}}
//
//Originally from [[Wikipedia:Projekt DotNetWikiBot Framework/Innocent bot/Ny parameter i Mall Ishockeyspelare]]
//Extensively modified by Lsj
//Ytterligare kladd av Lavallen igen
//Samt lite mindre kladd av Hangsna
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 DotNetWikiBot;
class MyBot : Bot
{
public static void Main()
{
Console.Write("Password: ");
string password = Console.ReadLine();
string botkonto = "Hangsna";
Site site = new Site("http://sv.wikipedia.org", botkonto, password);
Site site2 = new Site("http://en.wikipedia.org", botkonto, password);
PageList pl = new PageList(site);
//Select how to get pages. Uncomment as needed.
//Find articles from a category
//pl.FillAllFromCategory("Män");
pl.FillAllFromCategory("Män");
//Find articles from all the links to a template, mostly useful on very small wikis
// pl.FillFromLinksToPage("Mall:Taxobox");
//Set specific article:
//Page pp = new Page(site, "Iloilo City");pl.Add(pp);
//Skip all namespaces except articles:
pl.RemoveNamespaces(new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,100,101});
pl.Sort();
Page pwork = new Page(site, "Användare:"+botkonto+"/UtansorteringMän");
pwork.Load();
pwork.text = "\n\n==Senast körd {{subst:CURRENTYEAR}}-{{subst:CURRENTMONTH}}-{{subst:CURRENTDAY2}}==\n";
Console.Write("Starta vid: ");
string start = Console.ReadLine();
foreach(Page p in pl)
{
if(p.title.CompareTo(start)>0)
{
try
{
p.Load();
}
catch (WebException e)
{
Console.WriteLine(e.Message);
continue;
}
string enwp = "";
string ordning = "obestämd";
string formula = "";
if (p.text.IndexOf("standardsortering", StringComparison.OrdinalIgnoreCase) < 0)
if (p.text.IndexOf("defaultsort", StringComparison.OrdinalIgnoreCase) < 0)
{
if(p.text.IndexOf("[[en:") != -1)
{
enwp = p.text.Substring(p.text.IndexOf("[[en:")+5);
enwp = enwp.Substring(0,enwp.IndexOf("]]"));
Page pen = new Page(site2, enwp);
pen.Load();
if (pen.text.IndexOf("defaultsort", StringComparison.OrdinalIgnoreCase) < 0)
enwp = "";
else
{
enwp = pen.text.Substring(pen.text.IndexOf("defaultsort", StringComparison.OrdinalIgnoreCase)+12);
enwp = enwp.Substring(0,enwp.IndexOf("}}"));
}
}
if(p.title.IndexOf(" av ") != -1 || p.title.IndexOf(" från ") != -1)
{
string[] t = p.title.Split(' ');
if(t[1] == "av" || t[1] == "från")
{
ordning = "rak";
formula = p.title;
}
}
if(ordning == "obestämd" && p.title.IndexOf("(") != -1) //Kollar om parantes finns öht i artikelnamnet
{
string[] t = p.title.Split(' ');
{
if(t[1].StartsWith("("))//Om andra ordet börjar med parantes
{
ordning = "rak";
formula = t[0];//Standardsorteringen blir bara första ordet
}
}
}
if(p.title.IndexOf(" gamle") != -1 || p.title.IndexOf(" yngre") != -1 || p.title.IndexOf(" store") != -1 || p.title.IndexOf(" äldre") != -1)
{
string[] t = p.title.Split(' ');
{
if(t[1] == "den" )//Om andra ordet börjar med "den"
{
ordning = "rak";
formula = p.title;//Standardsorteringen blir artikelnamnet
}
}
}
// Här lägger du lämpligen andra rutiner för automagiska sparningar
if(ordning == "obestämd")
{
string[] t = p.title.Split(' ');
if(t.Length == 1)
{
ordning = "rak";
formula = p.title;
}
if(t.Length == 2)
{
Console.WriteLine("Artikelinnehåll:");
Console.WriteLine(p.text);
Console.WriteLine("Artikel: "+p.title);
if(enwp != "")
Console.WriteLine("Enwp har sorteringen: "+enwp);
else
Console.WriteLine("Enwp har ingen artikel eller sortering där saknas.");
Console.Write("Rak/Omvänd/Kommaterat/Annat? (R/O/K/A):");
string input = Console.ReadLine();
if(input.ToLower().StartsWith("r"))
{
ordning = "rak";
formula = p.title;
}
if(input.ToLower().StartsWith("o"))
{
ordning = "omvänd";
formula = t[1]+", "+t[0];
}
if(input.ToLower().StartsWith("k"))
{
ordning = "kommaterad";
formula = t[0]+", "+t[1];
}
}
}
if(ordning == "obestämd" && enwp != "")
{
Console.WriteLine("Artikelinnehåll:");
Console.WriteLine(p.text);
Console.WriteLine("Artikel: "+p.title);
Console.WriteLine("Sorteringen på enwp är: "+enwp);
Console.Write("Använda samma som enwp? (J/N):");
string input = Console.ReadLine();
if(input.ToLower().StartsWith("j") && input.Length < 2) //lägger till "&& input.Length < 2"
{
ordning = "enwp";
formula = enwp;
}
else //
if(input.Length > 2) //
{ //
ordning = "egen"; //
formula = input; //
} //
}
if(ordning == "obestämd")
{
Console.WriteLine("Artikelinnehåll:");
Console.WriteLine(p.text);
Console.WriteLine("Artikel: "+p.title);
if(enwp != "")
Console.WriteLine("Enwp har sorteringen: "+enwp);
else
Console.WriteLine("Enwp har ingen artikel eller sortering saknas.");
Console.Write("Egna ideer (tryck bara retur om du inte har några just nu!):");
string input = Console.ReadLine();
if(input != "")
{
ordning = "egen";
formula = input;
}
}
if(ordning != "obestämd")
{
int s = p.text.ToLower().IndexOf("[[kategori:");
formula = formula.Replace("í", "i");
formula = formula.Replace("ì", "i");
formula = formula.Replace("Í", "I");
formula = formula.Replace("Ì", "I");
formula = formula.Replace("é", "e");
formula = formula.Replace("è", "e");
formula = formula.Replace("ë", "e");
formula = formula.Replace("Ë", "E");
formula = formula.Replace("É", "E");
formula = formula.Replace("È", "E");
formula = formula.Replace("á", "a");
formula = formula.Replace("à", "a");
formula = formula.Replace("Á", "A");
formula = formula.Replace("À", "A");
formula = formula.Replace("ñ", "n");
formula = formula.Replace("Ñ", "N");
formula = formula.Replace("ó", "o");
formula = formula.Replace("ō", "o");
formula = formula.Replace("ô", "o");
formula = formula.Replace("Ó", "O");
formula = formula.Replace("Ô", "O");
formula = formula.Replace("æ", "ä");
formula = formula.Replace("ř", "r");
formula = formula.Replace("ŕ", "r");
formula = formula.Replace("Ŕ", "R");
formula = formula.Replace("Ş", "S");
formula = formula.Replace("ş", "s");
formula = formula.Replace("Ŝ", "S");
formula = formula.Replace("š", "s");
formula = formula.Replace("ü", "y");
formula = formula.Replace("Ü", "Y");
formula = formula.Replace("ć", "c");
formula = formula.Replace("ç", "c");
formula = formula.Replace("Ç", "C");
p.text = p.text.Substring(0,s)+"{{STANDARDSORTERING:"+formula+"}}\n"+p.text.Substring(s);
p.Save(p.text, "{{STANDARDSORTERING:"+formula+"}}", true);
Console.WriteLine("Sparad med "+formula+", fortsätter");
}
else
pwork.text += "\n* [[" + p.title + "]]";
}
}
}
bool saved = false;
while (!saved)
{
try
{
pwork.Save();
saved = true;
}
catch (WebException e)
{
Console.WriteLine(e.Message);
}
}
}
}