Hoppa till innehållet

Wikipedia:Projekt DotNetWikiBot Framework/Lsjbot/CreateFromTagalog

Från Wikipedia
//Originally from [[Wikipedia:Projekt DotNetWikiBot Framework/Innocent bot/Ny parameter i Mall Ishockeyspelare]]
//Extensively modified by Lsj

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
{
	private string CleanLink(string origlink)
	{
        string sbrack = "[]'† ?";
        char[] brackets = sbrack.ToCharArray();
        string s = origlink.Trim(brackets);
        if (s.Contains("|"))
            s = s.Remove(s.IndexOf("|"));
        return s;
	}
        
	public static void Main()
	{
        Console.Write("Password: ");
        string password = Console.ReadLine();
        Site svsite = new Site("http://sv.wikipedia.org", "Lsjbot", password);
        Site tlsite = new Site("http://tl.wikipedia.org", "Lsjbot", password);
        Site cmsite = new Site("http://commons.wikimedia.org", "Lsjbot", password);
        PageList pl = new PageList(tlsite);

        

        //Select how to get pages. Uncomment as needed.

        //Find articles from a category
        pl.FillFromCategoryTree("Mga bayan at lungsod sa Pilipinas");

        //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(tlsite, "Agdangan, Quezon");pl.Add(pp);

        //Skip all namespaces except regular articles:
        pl.RemoveNamespaces(new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,100,101});
        

        Dictionary<string, string> provinsdict = new Dictionary<string, string>(); 
        Dictionary<string, string> paramdict = new Dictionary<string, string>();
        Dictionary<string, string> regiondict = new Dictionary<string, string>();
        Dictionary<string, string> islanddict = new Dictionary<string, string>();

        string sr1 = "Abra (provins)"; string er1 = "Kordiljärernas administrativa region"; regiondict.Add(sr1, er1);
        string sr2 = "Agusan del Norte"; string er2 = "Caraga"; regiondict.Add(sr2, er2);
        string sr3 = "Agusan del Sur"; string er3 = "Caraga"; regiondict.Add(sr3, er3);
        string sr4 = "Aklan"; string er4 = "Västra Visayas"; regiondict.Add(sr4, er4);
        string sr5 = "Albay"; string er5 = "Bikolregionen"; regiondict.Add(sr5, er5);
        string sr6 = "Antique (provins)"; string er6 = "Västra Visayas"; regiondict.Add(sr6, er6);
        string sr7 = "Apayao"; string er7 = "Kordiljärernas administrativa region"; regiondict.Add(sr7, er7);
        string sr8 = "Aurora (provins)"; string er8 = "Centrala Luzon"; regiondict.Add(sr8, er8);
        string sr9 = "Basilan (provins)"; string er9 = "Muslimska Mindanao"; regiondict.Add(sr9, er9);
        string sr10 = "Bataan"; string er10 = "Centrala Luzon"; regiondict.Add(sr10, er10);
        string sr11 = "Batanes"; string er11 = "Cagayandalen"; regiondict.Add(sr11, er11);
        string sr12 = "Batangas"; string er12 = "CALABARZON"; regiondict.Add(sr12, er12);
        string sr13 = "Benguet"; string er13 = "Kordiljärernas administrativa region"; regiondict.Add(sr13, er13);
        string sr14 = "Bergsprovinsen"; string er14 = "Kordiljärernas administrativa region"; regiondict.Add(sr14, er14);
        string sr15 = "Biliran (provins)"; string er15 = "Östra Visayas"; regiondict.Add(sr15, er15);
        string sr16 = "Bohol"; string er16 = "Centrala Visayas"; regiondict.Add(sr16, er16);
        string sr17 = "Bukidnon"; string er17 = "Norra Mindanao"; regiondict.Add(sr17, er17);
        string sr18 = "Bulacan"; string er18 = "Centrala Luzon"; regiondict.Add(sr18, er18);
        string sr19 = "Cagayan"; string er19 = "Cagayandalen"; regiondict.Add(sr19, er19);
        string sr20 = "Camarines Norte"; string er20 = "Bikolregionen"; regiondict.Add(sr20, er20);
        string sr21 = "Camarines Sur"; string er21 = "Bikolregionen"; regiondict.Add(sr21, er21);
        string sr22 = "Camiguin"; string er22 = "Norra Mindanao"; regiondict.Add(sr22, er22);
        string sr23 = "Capiz"; string er23 = "Västra Visayas"; regiondict.Add(sr23, er23);
        string sr24 = "Catanduanes"; string er24 = "Bikolregionen"; regiondict.Add(sr24, er24);
        string sr25 = "Cavite"; string er25 = "CALABARZON"; regiondict.Add(sr25, er25);
        string sr26 = "Cebu"; string er26 = "Centrala Visayas"; regiondict.Add(sr26, er26);
        string sr27 = "Composteladalen"; string er27 = "Davaoregionen"; regiondict.Add(sr27, er27);
        string sr28 = "Cotabato"; string er28 = "SOCCSKSARGEN"; regiondict.Add(sr28, er28);
        string sr29 = "Davao del Norte"; string er29 = "Davaoregionen"; regiondict.Add(sr29, er29);
        string sr30 = "Davao del Sur"; string er30 = "Davaoregionen"; regiondict.Add(sr30, er30);
        string sr31 = "Davao Oriental"; string er31 = "Davaoregionen"; regiondict.Add(sr31, er31);
        string sr32 = "Dinagatöarna (provins)"; string er32 = "Caraga"; regiondict.Add(sr32, er32);
        string sr33 = "Guimaras"; string er33 = "Västra Visayas"; regiondict.Add(sr33, er33);
        string sr34 = "Ifugao"; string er34 = "Kordiljärernas administrativa region"; regiondict.Add(sr34, er34);
        string sr35 = "Iloilo (provins)"; string er35 = "Västra Visayas"; regiondict.Add(sr35, er35);
        string sr36 = "Isabela (provins)"; string er36 = "Cagayandalen"; regiondict.Add(sr36, er36);
        string sr37 = "Kalinga"; string er37 = "Kordiljärernas administrativa region"; regiondict.Add(sr37, er37);
        string sr38 = "La Union (provins)"; string er38 = "Ilocosregionen"; regiondict.Add(sr38, er38);
        string sr39 = "Laguna (provins)"; string er39 = "CALABARZON"; regiondict.Add(sr39, er39);
        string sr40 = "Lanao del Norte"; string er40 = "Norra Mindanao"; regiondict.Add(sr40, er40);
        string sr41 = "Lanao del Sur"; string er41 = "Muslimska Mindanao"; regiondict.Add(sr41, er41);
        string sr42 = "Leyte (provins)"; string er42 = "Östra Visayas"; regiondict.Add(sr42, er42);
        string sr43 = "Maguindanao"; string er43 = "Muslimska Mindanao"; regiondict.Add(sr43, er43);
        string sr44 = "Marinduque"; string er44 = "MIMAROPA"; regiondict.Add(sr44, er44);
        string sr45 = "Masbate (provins)"; string er45 = "Bikolregionen"; regiondict.Add(sr45, er45);
        string sr46 = "Misamis Occidental"; string er46 = "Norra Mindanao"; regiondict.Add(sr46, er46);
        string sr47 = "Misamis Oriental"; string er47 = "Norra Mindanao"; regiondict.Add(sr47, er47);
        string sr48 = "Negros Occidental"; string er48 = "Västra Visayas"; regiondict.Add(sr48, er48);
        string sr49 = "Negros Oriental"; string er49 = "Centrala Visayas"; regiondict.Add(sr49, er49);
        string sr50 = "Norra Ilocos"; string er50 = "Ilocosregionen"; regiondict.Add(sr50, er50);
        string sr51 = "Norra Samar"; string er51 = "Östra Visayas"; regiondict.Add(sr51, er51);
        string sr52 = "Nueva Ecija"; string er52 = "Centrala Luzon"; regiondict.Add(sr52, er52);
        string sr53 = "Nueva Vizcaya"; string er53 = "Cagayandalen"; regiondict.Add(sr53, er53);
        string sr54 = "Occidental Mindoro"; string er54 = "MIMAROPA"; regiondict.Add(sr54, er54);
        string sr55 = "Oriental Mindoro"; string er55 = "MIMAROPA"; regiondict.Add(sr55, er55);
        string sr56 = "Palawan"; string er56 = "MIMAROPA"; regiondict.Add(sr56, er56);
        string sr57 = "Pampanga"; string er57 = "Centrala Luzon"; regiondict.Add(sr57, er57);
        string sr58 = "Pangasinan (provins)"; string er58 = "Ilocosregionen"; regiondict.Add(sr58, er58);
        string sr59 = "Quezon"; string er59 = "CALABARZON"; regiondict.Add(sr59, er59);
        string sr60 = "Quirino"; string er60 = "Cagayandalen"; regiondict.Add(sr60, er60);
        string sr61 = "Rizal"; string er61 = "CALABARZON"; regiondict.Add(sr61, er61);
        string sr62 = "Romblon"; string er62 = "MIMAROPA"; regiondict.Add(sr62, er62);
        string sr63 = "Samar (provins)"; string er63 = "Östra Visayas"; regiondict.Add(sr63, er63);
        string sr64 = "Sarangani (provins)"; string er64 = "SOCCSKSARGEN"; regiondict.Add(sr64, er64);
        string sr65 = "Siquijor (provins)"; string er65 = "Centrala Visayas"; regiondict.Add(sr65, er65);
        string sr66 = "Sorsogon (provins)"; string er66 = "Bikolregionen"; regiondict.Add(sr66, er66);
        string sr67 = "Sultan Kudarat"; string er67 = "SOCCSKSARGEN"; regiondict.Add(sr67, er67);
        string sr68 = "Sulu (provins)"; string er68 = "Muslimska Mindanao"; regiondict.Add(sr68, er68);
        string sr69 = "Surigao del Norte"; string er69 = "Caraga"; regiondict.Add(sr69, er69);
        string sr70 = "Surigao del Sur"; string er70 = "Caraga"; regiondict.Add(sr70, er70);
        string sr71 = "Södra Cotabato"; string er71 = "SOCCSKSARGEN"; regiondict.Add(sr71, er71);
        string sr72 = "Södra Ilocos"; string er72 = "Ilocosregionen"; regiondict.Add(sr72, er72);
        string sr73 = "Södra Leyte"; string er73 = "Östra Visayas"; regiondict.Add(sr73, er73);
        string sr74 = "Tarlac"; string er74 = "Centrala Luzon"; regiondict.Add(sr74, er74);
        string sr75 = "Tawi-Tawi"; string er75 = "Muslimska Mindanao"; regiondict.Add(sr75, er75);
        string sr76 = "Zambales"; string er76 = "Centrala Luzon"; regiondict.Add(sr76, er76);
        string sr77 = "Zamboanga del Norte"; string er77 = "Zamboangahalvön"; regiondict.Add(sr77, er77);
        string sr78 = "Zamboanga del Sur"; string er78 = "Zamboangahalvön"; regiondict.Add(sr78, er78);
        string sr79 = "Zamboanga Sibugay"; string er79 = "Zamboangahalvön"; regiondict.Add(sr79, er79);
        string sr80 = "Östra Samar"; string er80 = "Östra Visayas"; regiondict.Add(sr80, er80);

        string sp1 = "Abra (provins)"; string ep1 = "Abra"; provinsdict.Add(ep1, sp1);
        string sp2 = "Agusan del Norte"; string ep2 = "Agusan del Norte"; provinsdict.Add(ep2, sp2);
        string sp3 = "Agusan del Sur"; string ep3 = "Agusan del Sur"; provinsdict.Add(ep3, sp3);
        string sp4 = "Aklan"; string ep4 = "Aklan (lalawigan)"; provinsdict.Add(ep4, sp4);
        string sp5 = "Albay"; string ep5 = "Albay"; provinsdict.Add(ep5, sp5);
        string sp6 = "Antique (provins)"; string ep6 = "Antique"; provinsdict.Add(ep6, sp6);
        string sp7 = "Apayao"; string ep7 = "Apayao"; provinsdict.Add(ep7, sp7);
        string sp8 = "Aurora (provins)"; string ep8 = "Aurora"; provinsdict.Add(ep8, sp8);
        string sp9 = "Basilan (provins)"; string ep9 = "Basilan"; provinsdict.Add(ep9, sp9);
        string sp10 = "Bataan"; string ep10 = "Bataan"; provinsdict.Add(ep10, sp10);
        string sp11 = "Batanes"; string ep11 = "Batanes"; provinsdict.Add(ep11, sp11);
        string sp12 = "Batangas"; string ep12 = "Batangas"; provinsdict.Add(ep12, sp12);
        string sp13 = "Benguet"; string ep13 = "Benguet"; provinsdict.Add(ep13, sp13);
        string sp14 = "Bergsprovinsen"; string ep14 = "Lalawigang Bulubundukin"; provinsdict.Add(ep14, sp14);
        string sp15 = "Biliran (provins)"; string ep15 = "Biliran"; provinsdict.Add(ep15, sp15);
        string sp16 = "Bohol"; string ep16 = "Bohol"; provinsdict.Add(ep16, sp16);
        string sp17 = "Bukidnon"; string ep17 = "Bukidnon"; provinsdict.Add(ep17, sp17);
        string sp18 = "Bulacan"; string ep18 = "Bulacan"; provinsdict.Add(ep18, sp18);
        string sp19 = "Cagayan"; string ep19 = "Cagayan (lalawigan)"; provinsdict.Add(ep19, sp19);
        string sp20 = "Camarines Norte"; string ep20 = "Camarines Norte"; provinsdict.Add(ep20, sp20);
        string sp21 = "Camarines Sur"; string ep21 = "Camarines Sur"; provinsdict.Add(ep21, sp21);
        string sp22 = "Camiguin"; string ep22 = "Camiguin"; provinsdict.Add(ep22, sp22);
        string sp23 = "Capiz"; string ep23 = "Capiz"; provinsdict.Add(ep23, sp23);
        string sp24 = "Catanduanes"; string ep24 = "Catanduanes"; provinsdict.Add(ep24, sp24);
        string sp25 = "Cavite"; string ep25 = "Kabite"; provinsdict.Add(ep25, sp25);
        string sp26 = "Cebu"; string ep26 = "Cebu (lalawigan)"; provinsdict.Add(ep26, sp26);
        string sp27 = "Composteladalen"; string ep27 = "Lambak ng Compostela"; provinsdict.Add(ep27, sp27);
        string sp28 = "Cotabato"; string ep28 = "Cotabato (lalawigan)"; provinsdict.Add(ep28, sp28);
        string sp29 = "Davao del Norte"; string ep29 = "Davao del Norte"; provinsdict.Add(ep29, sp29);
        string sp30 = "Davao del Sur"; string ep30 = "Davao del Sur"; provinsdict.Add(ep30, sp30);
        string sp31 = "Davao Oriental"; string ep31 = "Davao Oriental"; provinsdict.Add(ep31, sp31);
        string sp32 = "Dinagatöarna (provins)"; string ep32 = "Kapuluang Dinagat"; provinsdict.Add(ep32, sp32);
        string sp33 = "Guimaras"; string ep33 = "Guimaras"; provinsdict.Add(ep33, sp33);
        string sp34 = "Ifugao"; string ep34 = "Ifugao"; provinsdict.Add(ep34, sp34);
        string sp35 = "Iloilo (provins)"; string ep35 = "Iloilo (lalawigan)"; provinsdict.Add(ep35, sp35);
        string sp36 = "Isabela (provins)"; string ep36 = "Isabela (lalawigan)"; provinsdict.Add(ep36, sp36);
        string sp37 = "Kalinga"; string ep37 = "Kalinga"; provinsdict.Add(ep37, sp37);
        string sp38 = "La Union (provins)"; string ep38 = "La Union"; provinsdict.Add(ep38, sp38);
        string sp39 = "Laguna (provins)"; string ep39 = "Laguna"; provinsdict.Add(ep39, sp39);
        string sp40 = "Lanao del Norte"; string ep40 = "Lanao del Norte"; provinsdict.Add(ep40, sp40);
        string sp41 = "Lanao del Sur"; string ep41 = "Lanao del Sur"; provinsdict.Add(ep41, sp41);
        string sp42 = "Leyte (provins)"; string ep42 = "Leyte"; provinsdict.Add(ep42, sp42);
        string sp43 = "Maguindanao"; string ep43 = "Maguindanao"; provinsdict.Add(ep43, sp43);
        string sp44 = "Marinduque"; string ep44 = "Marinduque"; provinsdict.Add(ep44, sp44);
        string sp45 = "Masbate (provins)"; string ep45 = "Masbate"; provinsdict.Add(ep45, sp45);
        string sp46 = "Misamis Occidental"; string ep46 = "Misamis Occidental"; provinsdict.Add(ep46, sp46);
        string sp47 = "Misamis Oriental"; string ep47 = "Misamis Oriental"; provinsdict.Add(ep47, sp47);
        string sp48 = "Negros Occidental"; string ep48 = "Negros Occidental"; provinsdict.Add(ep48, sp48);
        string sp49 = "Negros Oriental"; string ep49 = "Negros Oriental"; provinsdict.Add(ep49, sp49);
        string sp50 = "Norra Ilocos"; string ep50 = "Ilocos Norte"; provinsdict.Add(ep50, sp50);
        string sp51 = "Norra Samar"; string ep51 = "Hilagang Samar"; provinsdict.Add(ep51, sp51);
        string sp52 = "Nueva Ecija"; string ep52 = "Nueva Ecija"; provinsdict.Add(ep52, sp52);
        string sp53 = "Nueva Vizcaya"; string ep53 = "Nueva Vizcaya"; provinsdict.Add(ep53, sp53);
        string sp54 = "Occidental Mindoro"; string ep54 = "Occidental Mindoro"; provinsdict.Add(ep54, sp54);
        string sp55 = "Oriental Mindoro"; string ep55 = "Oriental Mindoro"; provinsdict.Add(ep55, sp55);
        string sp56 = "Palawan"; string ep56 = "Palawan"; provinsdict.Add(ep56, sp56);
        string sp57 = "Pampanga"; string ep57 = "Pampanga"; provinsdict.Add(ep57, sp57);
        string sp58 = "Pangasinan (provins)"; string ep58 = "Pangasinan"; provinsdict.Add(ep58, sp58);
        string sp59 = "Quezon"; string ep59 = "Quezon"; provinsdict.Add(ep59, sp59);
        string sp60 = "Quirino"; string ep60 = "Quirino"; provinsdict.Add(ep60, sp60);
        string sp61 = "Rizal"; string ep61 = "Rizal (lalawigan)"; provinsdict.Add(ep61, sp61);
        string sp62 = "Romblon"; string ep62 = "Romblon"; provinsdict.Add(ep62, sp62);
        string sp63 = "Samar (provins)"; string ep63 = "Samar (lalawigan)"; provinsdict.Add(ep63, sp63);
        string sp64 = "Sarangani (provins)"; string ep64 = "Sarangani"; provinsdict.Add(ep64, sp64);
        string sp65 = "Siquijor (provins)"; string ep65 = "Siquijor"; provinsdict.Add(ep65, sp65);
        string sp66 = "Sorsogon (provins)"; string ep66 = "Sorsogon"; provinsdict.Add(ep66, sp66);
        string sp67 = "Sultan Kudarat"; string ep67 = "Sultan Kudarat"; provinsdict.Add(ep67, sp67);
        string sp68 = "Sulu (provins)"; string ep68 = "Sulu"; provinsdict.Add(ep68, sp68);
        string sp69 = "Surigao del Norte"; string ep69 = "Surigao del Norte"; provinsdict.Add(ep69, sp69);
        string sp70 = "Surigao del Sur"; string ep70 = "Surigao del Sur"; provinsdict.Add(ep70, sp70);
        string sp71 = "Södra Cotabato"; string ep71 = "Timog Cotabato"; provinsdict.Add(ep71, sp71);
        string sp72 = "Södra Ilocos"; string ep72 = "Ilocos Sur"; provinsdict.Add(ep72, sp72);
        string sp73 = "Södra Leyte"; string ep73 = "Katimugang Leyte"; provinsdict.Add(ep73, sp73);
        string sp74 = "Tarlac"; string ep74 = "Tarlac"; provinsdict.Add(ep74, sp74);
        string sp75 = "Tawi-Tawi"; string ep75 = "Tawi-Tawi"; provinsdict.Add(ep75, sp75);
        string sp76 = "Zambales"; string ep76 = "Zambales"; provinsdict.Add(ep76, sp76);
        string sp77 = "Zamboanga del Norte"; string ep77 = "Zamboanga del Norte"; provinsdict.Add(ep77, sp77);
        string sp78 = "Zamboanga del Sur"; string ep78 = "Zamboanga del Sur"; provinsdict.Add(ep78, sp78);
        string sp79 = "Zamboanga Sibugay"; string ep79 = "Zamboanga Sibugay"; provinsdict.Add(ep79, sp79);
        string sp80 = "Östra Samar"; string ep80 = "Silangang Samar"; provinsdict.Add(ep80, sp80);

string si1 = "area_water_km2"; string sg1 = "yta_vatten"; paramdict.Add(si1, sg1);
string si2 = "area_land_km2"; string sg2 = "yta_land"; paramdict.Add(si2, sg2);
string si3 = "areakm2"; string sg3 = "yta"; paramdict.Add(si3, sg3);
string si4 = "website"; string sg4 = "url"; paramdict.Add(si4, sg4);
string si5 = "timezone_DST"; string sg5 = "tidszon_DST"; paramdict.Add(si5, sg5);
string si6 = "timezone"; string sg6 = "tidszon"; paramdict.Add(si6, sg6);
string si7 = "province"; string sg7 = "indelning"; paramdict.Add(si7, sg7);
string si8 = "mayor"; string sg8 = "styre"; paramdict.Add(si8, sg8);
string si9 = "sealfile"; string sg9 = "sigill"; paramdict.Add(si9, sg9);
string si11 = "longs"; string sg11 = "long_s"; paramdict.Add(si11, sg11);
string si12 = "longm"; string sg12 = "long_m"; paramdict.Add(si12, sg12);
string si13 = "longd"; string sg13 = "long_g"; paramdict.Add(si13, sg13);
string si14 = "longEW"; string sg14 = "long_EW"; paramdict.Add(si14, sg14);
string si15 = "lats"; string sg15 = "lat_s"; paramdict.Add(si15, sg15);
string si16 = "latNS"; string sg16 = "lat_NS"; paramdict.Add(si16, sg16);
string si17 = "latm"; string sg17 = "lat_m"; paramdict.Add(si17, sg17);
string si18 = "latd"; string sg18 = "lat_g"; paramdict.Add(si18, sg18);
string si19 = "locatormapfile"; string sg19 = "bild"; paramdict.Add(si19, sg19);
string si20 = "infoboxtitle"; string sg20 = "annat_namn"; paramdict.Add(si20, sg20);
string si21 = "population_as_of"; string sg21 = "folkmängd_år"; paramdict.Add(si21, sg21);
string si22 = "population_footnotes"; string sg22 = "folkmängd_not"; paramdict.Add(si22, sg22);
string si23 = "population_total"; string sg23 = "folkmängd"; paramdict.Add(si23, sg23);
string si24 = "image_flag"; string sg24 = "fana"; paramdict.Add(si24, sg24);
string si26 = "image_caption"; string sg26 = "bildtext"; paramdict.Add(si26, sg26);

string is1 = "Abra (provins)"; string ii1 = "Luzon"; islanddict.Add(is1, ii1);
string is2 = "Agusan del Norte"; string ii2 = "Mindanao"; islanddict.Add(is2, ii2);
string is3 = "Agusan del Sur"; string ii3 = "Mindanao"; islanddict.Add(is3, ii3);
string is4 = "Aklan"; string ii4 = "Panay"; islanddict.Add(is4, ii4);
string is5 = "Albay"; string ii5 = "Luzon"; islanddict.Add(is5, ii5);
string is6 = "Antique (provins)"; string ii6 = "Panay"; islanddict.Add(is6, ii6);
string is7 = "Apayao"; string ii7 = "Luzon"; islanddict.Add(is7, ii7);
string is8 = "Aurora (provins)"; string ii8 = "Luzon"; islanddict.Add(is8, ii8);
string is9 = "Basilan (provins)"; string ii9 = "Basilan"; islanddict.Add(is9, ii9);
string is10 = "Bataan"; string ii10 = "Luzon"; islanddict.Add(is10, ii10);
string is11 = "Batanes"; string ii11 = "Luzon"; islanddict.Add(is11, ii11);
string is12 = "Batangas"; string ii12 = "Luzon"; islanddict.Add(is12, ii12);
string is13 = "Benguet"; string ii13 = "Luzon"; islanddict.Add(is13, ii13);
string is14 = "Bergsprovinsen"; string ii14 = "Luzon"; islanddict.Add(is14, ii14);
string is15 = "Biliran (provins)"; string ii15 = "Biliran"; islanddict.Add(is15, ii15);
string is16 = "Bohol"; string ii16 = ""; islanddict.Add(is16, ii16);
string is17 = "Bukidnon"; string ii17 = "Mindanao"; islanddict.Add(is17, ii17);
string is18 = "Bulacan"; string ii18 = "Luzon"; islanddict.Add(is18, ii18);
string is19 = "Cagayan"; string ii19 = "Luzon"; islanddict.Add(is19, ii19);
string is20 = "Camarines Norte"; string ii20 = "Luzon"; islanddict.Add(is20, ii20);
string is21 = "Camarines Sur"; string ii21 = "Luzon"; islanddict.Add(is21, ii21);
string is22 = "Camiguin"; string ii22 = "Mindanao"; islanddict.Add(is22, ii22);
string is23 = "Capiz"; string ii23 = "Panay"; islanddict.Add(is23, ii23);
string is24 = "Catanduanes"; string ii24 = "Luzon"; islanddict.Add(is24, ii24);
string is25 = "Cavite"; string ii25 = "Luzon"; islanddict.Add(is25, ii25);
string is26 = "Cebu"; string ii26 = ""; islanddict.Add(is26, ii26);
string is27 = "Composteladalen"; string ii27 = "Mindanao"; islanddict.Add(is27, ii27);
string is28 = "Cotabato"; string ii28 = "Mindanao"; islanddict.Add(is28, ii28);
string is29 = "Davao del Norte"; string ii29 = "Mindanao"; islanddict.Add(is29, ii29);
string is30 = "Davao del Sur"; string ii30 = "Mindanao"; islanddict.Add(is30, ii30);
string is31 = "Davao Oriental"; string ii31 = "Mindanao"; islanddict.Add(is31, ii31);
string is32 = "Dinagatöarna (provins)"; string ii32 = ""; islanddict.Add(is32, ii32);
string is33 = "Guimaras"; string ii33 = ""; islanddict.Add(is33, ii33);
string is34 = "Ifugao"; string ii34 = "Luzon"; islanddict.Add(is34, ii34);
string is35 = "Iloilo (provins)"; string ii35 = "Panay"; islanddict.Add(is35, ii35);
string is36 = "Isabela (provins)"; string ii36 = "Luzon"; islanddict.Add(is36, ii36);
string is37 = "Kalinga"; string ii37 = "Luzon"; islanddict.Add(is37, ii37);
string is38 = "La Union (provins)"; string ii38 = "Luzon"; islanddict.Add(is38, ii38);
string is39 = "Laguna (provins)"; string ii39 = "Luzon"; islanddict.Add(is39, ii39);
string is40 = "Lanao del Norte"; string ii40 = "Mindanao"; islanddict.Add(is40, ii40);
string is41 = "Lanao del Sur"; string ii41 = "Mindanao"; islanddict.Add(is41, ii41);
string is42 = "Leyte (provins)"; string ii42 = "Leyte"; islanddict.Add(is42, ii42);
string is43 = "Maguindanao"; string ii43 = "Mindanao"; islanddict.Add(is43, ii43);
string is44 = "Marinduque"; string ii44 = ""; islanddict.Add(is44, ii44);
string is45 = "Masbate (provins)"; string ii45 = ""; islanddict.Add(is45, ii45);
string is46 = "Misamis Occidental"; string ii46 = "Mindanao"; islanddict.Add(is46, ii46);
string is47 = "Misamis Oriental"; string ii47 = "Mindanao"; islanddict.Add(is47, ii47);
string is48 = "Negros Occidental"; string ii48 = "Negros"; islanddict.Add(is48, ii48);
string is49 = "Negros Oriental"; string ii49 = "Negros"; islanddict.Add(is49, ii49);
string is50 = "Norra Ilocos"; string ii50 = "Luzon"; islanddict.Add(is50, ii50);
string is51 = "Norra Samar"; string ii51 = "Samar"; islanddict.Add(is51, ii51);
string is52 = "Nueva Ecija"; string ii52 = "Luzon"; islanddict.Add(is52, ii52);
string is53 = "Nueva Vizcaya"; string ii53 = "Luzon"; islanddict.Add(is53, ii53);
string is54 = "Occidental Mindoro"; string ii54 = "Mindoro"; islanddict.Add(is54, ii54);
string is55 = "Oriental Mindoro"; string ii55 = "Mindoro"; islanddict.Add(is55, ii55);
string is56 = "Palawan"; string ii56 = ""; islanddict.Add(is56, ii56);
string is57 = "Pampanga"; string ii57 = "Luzon"; islanddict.Add(is57, ii57);
string is58 = "Pangasinan (provins)"; string ii58 = "Luzon"; islanddict.Add(is58, ii58);
string is59 = "Quezon"; string ii59 = "Luzon"; islanddict.Add(is59, ii59);
string is60 = "Quirino"; string ii60 = "Luzon"; islanddict.Add(is60, ii60);
string is61 = "Rizal"; string ii61 = "Luzon"; islanddict.Add(is61, ii61);
string is62 = "Romblon"; string ii62 = ""; islanddict.Add(is62, ii62);
string is63 = "Samar (provins)"; string ii63 = ""; islanddict.Add(is63, ii63);
string is64 = "Sarangani (provins)"; string ii64 = "Mindanao"; islanddict.Add(is64, ii64);
string is65 = "Siquijor (provins)"; string ii65 = ""; islanddict.Add(is65, ii65);
string is66 = "Sorsogon (provins)"; string ii66 = "Luzon"; islanddict.Add(is66, ii66);
string is67 = "Sultan Kudarat"; string ii67 = "Mindanao"; islanddict.Add(is67, ii67);
string is68 = "Sulu (provins)"; string ii68 = "Suluöarna"; islanddict.Add(is68, ii68);
string is69 = "Surigao del Norte"; string ii69 = "Mindanao"; islanddict.Add(is69, ii69);
string is70 = "Surigao del Sur"; string ii70 = "Mindanao"; islanddict.Add(is70, ii70);
string is71 = "Södra Cotabato"; string ii71 = "Mindanao"; islanddict.Add(is71, ii71);
string is72 = "Södra Ilocos"; string ii72 = "Luzon"; islanddict.Add(is72, ii72);
string is73 = "Södra Leyte"; string ii73 = "Leyte"; islanddict.Add(is73, ii73);
string is74 = "Tarlac"; string ii74 = "Luzon"; islanddict.Add(is74, ii74);
string is75 = "Tawi-Tawi"; string ii75 = "Suluöarna"; islanddict.Add(is75, ii75);
string is76 = "Zambales"; string ii76 = "Luzon"; islanddict.Add(is76, ii76);
string is77 = "Zamboanga del Norte"; string ii77 = "Mindanao"; islanddict.Add(is77, ii77);
string is78 = "Zamboanga del Sur"; string ii78 = "Mindanao"; islanddict.Add(is78, ii78);
string is79 = "Zamboanga Sibugay"; string ii79 = "Mindanao"; islanddict.Add(is79, ii79);
string is80 = "Östra Samar"; string ii80 = "Samar"; islanddict.Add(is80, ii80);

string sbrack = "[]'† ?";
char[] brackets = sbrack.ToCharArray();
                                    

int nfound = 0;

		foreach(Page p in pl)
		{
			p.Load();
        
            //Remove comments and leading blanks, otherwise the template finding doesn't work properly:

            string str = p.text;
            int startPos, endPos, len = 0;
            while ((startPos = str.LastIndexOf("<!")) != -1)
            {
                endPos = str.IndexOf("->", startPos);
                len = (endPos != -1) ? endPos - startPos + 2 : 2;
                //Console.WriteLine("Removing " + str.Substring(startPos, len));
                str = str.Remove(startPos, len);
                //str = str.Insert(startPos, new String('_', len));
            }
            while (str.Contains("{{ "))
            {
                str = str.Replace("{{ ", "{{");
            }
            p.text = str;

            Dictionary<string, string> newparamdict = new Dictionary<string, string>(); 
            Dictionary<string, string> oldparameters;

            string templateTitle = "Infobox Philippine municipality 2";
            Regex templateTitleRegex = new Regex("^\\s*(" +
                Bot.Capitalize(Regex.Escape(templateTitle)) + "|" +
                Bot.Uncapitalize(Regex.Escape(templateTitle)) +
                ")\\s*\\|");
            string coorTitle = "coor title dm";
            Regex coorTitleRegex = new Regex("^\\s*(" +
                Bot.Capitalize(Regex.Escape(coorTitle)) + "|" +
                Bot.Uncapitalize(Regex.Escape(coorTitle)) +
                ")\\s*\\|");

            bool foundtemplate = false;
            string island = "";
            string nbgy = "";
                
            foreach (string template in p.GetTemplatesWithParams())
            {
                if (template.Length > 40)
                    Console.WriteLine(template.Substring(0, 40));
                else
                    Console.WriteLine(template);

                if (templateTitleRegex.IsMatch(template))
                {
                    //Ok, found the right template. Now get params:
                    oldparameters = tlsite.ParseTemplate(template);
                    Console.WriteLine("op:");
                    foundtemplate = true;
                    nfound++;
                    foreach (string op in oldparameters.Keys)
                    {
                        if (paramdict.ContainsKey(op))
                        {
                            //Console.WriteLine(op);
                            switch (paramdict[op])
                            {
                                case "region_type":
                                    newparamdict.Add(paramdict[op], "[[Filippinernas regioner|Region]]");
                                    break;
                                case "district_type":
                                    newparamdict.Add(paramdict[op], "[[Filippinernas provinser|Provins]]");
                                    break;
                                case "indelning":
                                    string cp = oldparameters[op].Trim(brackets);
                                    if (cp.Contains("]"))
                                        cp = cp.Remove(cp.IndexOf("]"));
                                    if (cp.Contains("|"))
                                        cp = cp.Remove(cp.IndexOf("|"));
                                    if (cp.Contains("("))
                                        cp = cp.Remove(cp.IndexOf("("));
                                    //string cp = CleanLink(oldparameters[op]);
                                    string spp = cp;
                                    if (provinsdict.ContainsKey(cp))
                                        spp = provinsdict[cp];
                                    else if (provinsdict.ContainsKey(cp+" (lalawigan)"))
                                        spp = provinsdict[cp + " (lalawigan)"];
                                    newparamdict.Add(paramdict[op], "[["+spp+"]]");
                                    if (regiondict.ContainsKey(spp))
                                    {
                                        newparamdict.Add("delstat", "[[" + regiondict[spp] + "]]");
                                        island = islanddict[spp];
                                    }
                                    break;
                                case "form":
                                    if (oldparameters[op].Contains("city"))
                                        newparamdict.Add(paramdict[op], "[[Stad]]");
                                    else if (oldparameters[op].Contains("City"))
                                        newparamdict.Add(paramdict[op], "[[Stad]]");
                                    else
                                        newparamdict.Add(paramdict[op], oldparameters[op]);
                                    break;
                                case "url":
                                    if (oldparameters[op].Contains("{{URL"))
                                    {
                                        string ccp = oldparameters[op].Replace("{{URL|", "[http:////").Replace("}}", "]");
                                        newparamdict.Add(paramdict[op], ccp);
                                    }
                                    else
                                        newparamdict.Add(paramdict[op], oldparameters[op]);
                                    break;
                                case "sigill":
                                case "bild":
                                    Page pcm = new Page(cmsite,"File:"+oldparameters[op]);
                                    //pcm.Load();
                                    //Console.WriteLine("LastUser: "+pcm.LastUser);
                                    //if ( pcm.Exists())
                                    //    newparamdict.Add(paramdict[op], oldparameters[op]);
                                    //else
                                    //    Console.WriteLine("Image not found " + oldparameters[op]);        
                                    string res = cmsite.site + cmsite.indexPath + "index.php?title=" +
				                    HttpUtility.UrlEncode("File:"+oldparameters[op]);
			                        string src = "";
			                        try 
                                    {
				                        src = cmsite.GetPageHTM(res);
			                        }
			                        catch (WebException e) {
				                        string message = e.Message;
                                        if (message.Contains(": (404) "))
                                        {		// Not Found
                                            Console.Error.WriteLine(Bot.Msg("Page \"{0}\" doesn't exist."), oldparameters[op]);
                                            Console.WriteLine("Image not found " + oldparameters[op]);
                                            break;
                                        }
                                        else
                                        {
                                            Console.Error.WriteLine(message);
                                            break;
                                        }
			                        }
			                        newparamdict.Add(paramdict[op], oldparameters[op]);
                                    break;
                                case "folkmängd_år":
                                    if (oldparameters[op].Contains("{{asof"))
                                        newparamdict.Add(paramdict[op], oldparameters[op].Replace("{{asof|", "").Replace("}}", ""));
                                    break;
                                default:
                                    newparamdict.Add(paramdict[op], oldparameters[op]);
                                    break;
                            }
                        }
                    }
                        //Console.WriteLine("np:");
                        //foreach (string np in newparamdict.Keys)
                        //    Console.WriteLine(np + " = " + newparamdict[np]);
                    
                    newparamdict.Add("land","Filippinerna");
                    newparamdict.Add("tidszon","[[UTC+8]]");
                    newparamdict.Add("styre_titel", "[[Borgmästare]]");
                    newparamdict.Add("form", "[[Kommun]]");

                    if (oldparameters.ContainsKey("barangays"))
                        nbgy = oldparameters["barangays"];
                    
                }
                else if (coorTitleRegex.IsMatch(template))
                {
                    oldparameters = tlsite.ParseTemplate(template);
                    //Console.WriteLine("op:");
                    nfound++;
                    foreach (string op in oldparameters.Keys)
                    {
                        //Console.WriteLine(op + ": " + oldparameters[op]);
                        switch (op)
                        {
                            case "0": if (newparamdict.ContainsKey("lat_g"))
                                         newparamdict["lat_g"] = oldparameters[op];
                                      else
                                        newparamdict.Add("lat_g", oldparameters[op]); 
                                      break;
                            case "1": if (newparamdict.ContainsKey("lat_m"))
                                          newparamdict["lat_m"] = oldparameters[op];
                                      else
                                          newparamdict.Add("lat_m", oldparameters[op]);
                                      break;
                            case "2": if (newparamdict.ContainsKey("lat_NS"))
                                          newparamdict["lat_NS"] = oldparameters[op];
                                      else
                                          newparamdict.Add("lat_NS", oldparameters[op]);
                                      break;
                            case "3": if (newparamdict.ContainsKey("long_g"))
                                          newparamdict["long_g"] = oldparameters[op];
                                      else
                                          newparamdict.Add("long_g", oldparameters[op]);
                                      break;
                            case "4": if (newparamdict.ContainsKey("long_m"))
                                          newparamdict["long_m"] = oldparameters[op];
                                      else
                                          newparamdict.Add("long_m", oldparameters[op]);
                                      break;
                            case "5": if (newparamdict.ContainsKey("long_EW"))
                                          newparamdict["long_EW"] = oldparameters[op];
                                      else
                                          newparamdict.Add("long_EW", oldparameters[op]);
                                      break;
                            default: break;

                        }
                    }
                    
                }
            }

            if (!foundtemplate)
            {
                Console.WriteLine("Template not found");
                continue;
            }
            //find swedish match:
            string geobox = "{{Stadsfakta|}}\n";
            string[] iw = p.GetInterWikiLinks();
            bool svexists = false; 
            
            foreach (string iws in iw)
            {
               if (iws.Contains("sv:"))
                {
                    string svtit = iws.Replace("sv:","");
                    Page psv = new Page(svsite,svtit);
                    psv.Load();
                    if (!psv.Exists())
                        break;
                    svexists = true;
                    string origtext = psv.text;
                    if (!psv.text.Contains("eobox") && !psv.text.Contains("tadsfakta"))
                    {

                        //Console.WriteLine("Filling params");
                        psv.text = geobox + psv.text;
                        foreach (string np in newparamdict.Keys)
                        {
                            //Console.WriteLine(np);
                            psv.SetTemplateParameter("Stadsfakta", np, newparamdict[np], true);
                        }
                    }
                    else
                        Console.WriteLine("Has box already");
                    //DONE!  Now save if needed.

                    Bot.editComment = "Fixar faktamall";
                    isMinorEdit = false;
                    if (psv.text != origtext)
                        psv.Save();
                    Thread.Sleep(4000);//milliseconds
        
                }

            }

            if (!svexists) //No Swedish article found; create one!
            {
                string provname = "";
                if (newparamdict.ContainsKey("indelning"))
                    provname = newparamdict["indelning"].Trim(brackets);
                if (provname.Contains(" ("))
                    provname = provname.Remove(provname.IndexOf(" ("));
                
                string svtit = p.title;
                if ( svtit.Contains(", "))
                    svtit = svtit.Remove(svtit.IndexOf(", "));
                newparamdict.Add("namn", svtit);

                Page psv = new Page(svsite, svtit);
                psv.Load();
                if (psv.Exists())
                {
                    //Försöker skapa särskiljningsled: '''Kommun (provins)'''
                    string svtit2 = svtit + " (" + provname + ")";
                    psv.title = svtit2;
                    psv.text = null;
                    psv.Load();
                    if (psv.Exists()) 
                        continue; //Om det inte ens funkar med särskiljning; skippa!
                }

                //Make stadsfakta-box:
                psv.text = geobox;
                foreach (string np in newparamdict.Keys)
                {
                    //Console.WriteLine(np);
                    psv.SetTemplateParameter("Stadsfakta", np, newparamdict[np], true);
                }
                
                //Make article text:

                psv.text = psv.text + "'''"+svtit+"''' (''"+newparamdict["annat_namn"]+"'') är en [[kommun]] i [[Filippinerna]]. ";
                string provlink = newparamdict["indelning"];
                if (provlink.Contains("("))
                    provlink = provlink.Replace("]]","|"+provname+"]]");
                if (island != "")
                    psv.text = psv.text + "Kommunen ligger på ön [[" + island + "]], och tillhör provinsen " + provlink + ". ";
                else
                    psv.text = psv.text + "Kommunen tillhör provinsen " + provlink + " och ligger på ön med samma namn. ";
                if ( newparamdict.ContainsKey("folkmängd_år"))
                   psv.text = psv.text + "Befolkningen uppgick år " + newparamdict["folkmängd_år"] + " till " + newparamdict["folkmängd"] + " personer. ";
                else if (newparamdict.ContainsKey("folkmängd"))
                    psv.text = psv.text + "Befolkningen uppgår till " + newparamdict["folkmängd"] + " personer.";
                psv.text = psv.text + "\n\n";
                
                //Barangays:

                bool bgytable = false;
                Regex bgyRegEx = new Regex("arangay *==");
                if ( bgyRegEx.IsMatch(p.text))
                //if ((p.text.Contains("==Mga Barangay=="))||(p.text.Contains("==Barangay=="))||(p.text.Contains("== Mga Barangay ==")))
                {
                    Console.WriteLine("Found bgy-match");
                    int nmb = p.text.IndexOf("arangay");
                    int nts = -1;
                    int nte = -1;
                    int extra = 0;
                    if (p.text.Contains("{|") && p.text.Contains("|}"))
                    {
                        nts = p.text.IndexOf("{|");
                        nte = p.text.IndexOf("|}");
                        extra = 2;
                    }
                    else if (p.text.Contains("<table") && p.text.Contains("/table>"))
                    {
                        nts = p.text.IndexOf("<table");
                        nte = p.text.IndexOf("/table>");
                        extra = 7;
                        
                    }
                    
                    if ((nts > nmb) && (nte > nts))
                        {
                            //Copy barangay-table
                            psv.text = psv.text + "== Barangayer ==\n";
                            if ( nbgy != "" )
                              psv.text = psv.text + svtit + " delas in i " + nbgy + " [[barangay]]er. \n\n";
                            psv.text = psv.text + p.text.Substring(nts, nte - nts + extra)+"\n\n";
                            bgytable = true;
                        }
                    
                }
                if (!bgytable && (nbgy!=""))
                    psv.text = psv.text + svtit + " delas in i " + nbgy + " [[barangay]]er. \n\n";

                //Categories:

                psv.text = psv.text + "[[Kategori:Orter i " + provname + "]]\n";

                //Interwiki:

                foreach (string iws in iw)
                {
                    if (!iws.Contains("sv:"))
                        psv.text = psv.text + "[[" + iws + "]]\n";
                }
                psv.text = psv.text + "[[tl:" + p.title + "]]\n";

                //botmall:

                psv.text = "{{robotskapad|Lsjbot|filippinska kommun|datum=2012-08}}\n" + psv.text;

                //DONE!  Now save the new article.

                Bot.editComment = "Skapar kommunartikel med bot";
                isMinorEdit = false;
                //Console.WriteLine("-----------");
                //Console.WriteLine(psv.text);
                psv.Save();
                Thread.Sleep(4000);//milliseconds
            }
            
              
        }
	}
}