import pywikibot
import re
from pywikibot import pagegenerators
site = pywikibot.Site('en', 'wikipedia')
resultpage = pywikibot.Page(site, u"User:Trialpears/Automatic biography short descriptions")
def extractfirst(text):
    i=0
    result=text
    result=re.sub("\[\[[Cc]ategory:[^\]]*]]","",result)
    result=re.sub("\[\[[Ff]ile:[^\]]*]]","",result)
    result=re.sub("\[\[[Ii]mage:[^\]]*]]","",result)
    result=re.sub("\n"," ",result)
    result=re.sub("==.*","",result)
    result=re.sub("''+","",result)
    result=re.sub("\[\[([^\|\]\[]*\|)?([^\|\]\[]*)]]",r"\2",result)
    while i < 5:
        result=re.sub("{{[^{}]*}}","",result)
        result=re.sub("\([^\(\)]*\)","",result)
        result=re.sub("<ref[^<>]*>[^<>]*<\/ref>","",result)
        result=re.sub("<ref[^<>]*\/>","",result)
        result=re.sub("<!--[^<>]*-->","",result)
        i+=1
    result=re.sub("\n","",result)
    result=re.sub("  *"," ",result)
    result=re.sub("(^.*?[.!?](?=\s[A-Z]|$)).*",r"\1",result)
    result=re.sub("^\s*","",result)
    result=re.sub("\s*(?=,|\.)","",result)
    result=re.sub("\s*$","",result)
    return result
def extractdescription(text):
    result=text
    if re.match('^(("?[A-Z][a-z]*"?|(Jr\.)),? )*?(is|was) (a|an) ',result):
        result=re.sub('^(("?[A-Z][a-z]*"?|(Jr\.)),? )*?(is|was) (a|an) (.*)',r"\6",result)
        result=re.sub(',? who .*',"",result)
        result=re.sub(',? known for .*',"",result)
        result=re.sub(',? currently .*',"",result)
        result=re.sub(',? as well .*',"",result)
        result=re.sub(',? better known .*',"",result)
        result=re.sub(',? best known .*',"",result)
        result=re.sub("\.$","",result)
        result=re.sub('([a-zA-Z])', lambda x: x.groups()[0].upper(), result, 1)
        result=re.sub(',\s*best',"",result)
        if len(result) <= 40:
            if re.match("(Afghan|Albanian|Algerian|Andorran|Angolan|and|Barbuda|Antiguan|Barbudan|Argentine|Armenian|Australian|Austrian|Azerbaijani|Azeri|Bahamas|Bahamian|Bahraini|Bengali|Barbadian|Belarusian|Belgian|Belizean|Beninese|Beninois|Bhutanese|Bolivian|Bosnian|Herzegovinian|Motswana|Botswanan|Brazilian|Bruneian|Bulgarian|Faso|Burkinabé|Burmese|Burundian|Verde|Cabo|Verdean|Cambodian|Cameroonian|Canadian|African|Chadian|Chilean|Chinese|Colombian|Comoran|Comorian|Congolese|Rican|Ivorian|Croatian|Cuban|Cypriot|Republic|Czech|Danish|Djiboutian|Dominican|Republic|Dominican|Timor|Timorese|Ecuadorian|Egyptian|Salvador|Salvadoran|Guinea|Equatorial|Guinean|Equatoguinean|Eritrean|Estonian|Ethiopian|Fijian|Finnish|French|Gabonese|The|Gambian|Georgian|German|Ghanaian|Gibraltar|Greek|Hellenic|Grenadian|Guatemalan|Guinean|Bissau|Guinean|Guyanese|Haitian|Honduran|Hungarian|Magyar|Icelandic|Indian|Indonesian|Iranian|Persian|Iraqi|Irish|Israeli|Italian|Coast|Ivorian|Jamaican|Japanese|Jordanian|Kazakhstani|Kazakh|Kenyan|Kiribati|Korea|North|Korean|Korea|South|Korean|Kuwaiti|Kyrgyzstani|Kyrgyz|Kirgiz|Kirghiz|Lao|Laotian|Latvian|Lettish|Lebanese|Basotho|Liberian|Libyan|Liechtensteiner|Lithuanian|Luxembourg|Luxembourgish|Republic|of|Macedonian|Malagasy|Malawian|Malaysian|Maldivian|Malian|Malinese|Maltese|Islands|Marshallese|Martiniquais|Martinican|Mauritanian|Mauritian|Mexican|Federated|States|of|Micronesian|Moldovan|Monégasque|Monacan|Mongolian|Montenegrin|Moroccan|Mozambican|Namibian|Nauruan|Nepali|Nepalese|Dutch|Netherlandic|Zealand|New|Zealand|NZ|Zelanian|Nicaraguan|Nigerien|Nigerian|Mariana|Islands|Northern|Marianan|Norwegian|Omani|Pakistani|Palauan|Palestinian|Panamanian|New|Guinea|Papua|New|Guinean|Papuan|Paraguayan|Peruvian|Filipino|Philippine|Polish|Portuguese|Rico|Puerto|Rican|Qatari|Romanian|Russian|Rwandan|Kitts|and|Nevis|Kittitian|or|Nevisian|Lucia|Saint|Lucian|Vincent|and|the|Grenadines|Saint|Vincentian|Vincentian|Samoan|Marino|Sammarinese|ão|Tomé|and|Príncipe|São|Toméan|Arabia|Saudi|Saudi|Arabian|Senegalese|Serbian|Seychellois|Leone|Sierra|Leonean|Singapore|Singaporean|Slovak|Slovenian|Slovene|Islands|Solomon|Island|Somali|Africa|South|African|Sudan|South|Sudanese|Spanish|Lanka|Sri|Lankan|Sudanese|Surinamese|Swazi|Swedish|Swiss|Syrian|Tajikistani|Tanzanian|Thai|Leste|Timorese|Togolese|Tokelauan|Tongan|and|Tobago|Trinidadian|or|Tobagonian|Tunisian|Turkish|Turkmen|Tuvaluan|Ugandan|Ukrainian|Arab|Emirates|Emirati|Emirian|Emiri|Kingdom|of|Great|Britain|and|Northern|Ireland|UK|British|States|of|America|United|States|U.S.|American|Uruguayan|Uzbekistani|Uzbek|Vanuatu|Vanuatuan|City|State|Vatican|Venezuelan|Vietnamese|Yemeni|Zambian|Zimbabwean)",result):
                global counter 
                counter += 1
                return result
    return False
counter = 1
for page in pywikibot.pagegenerators.SearchPageGenerator('intitle:"Adrian Vandenberg"'):
    savecount = 0
    if extractdescription(extractfirst(page.text)) is not False:
        description="{{short description|"+extractdescription(extractfirst(page.text))+"|bot=PearBOT 5}}\n"
        page.text=description+page.text
        print(extractfirst(page.text))
        print(description)
        print(savecount)
        if savecount<1:
            page.save("Adding automatically generated short description. Bot in trial see [[Wikipedia:Bots/Requests for approval/PearBOT 5|BRFA]]")
            savecount = savecount + 1
Adrian Vandenberg is a Dutch rock guitarist, best known for his tenure as one of the guitarists in Whitesnake during their successful late 1980s period and the band Vandenberg which he started in 1981.
{{short description|Dutch rock guitarist|bot=PearBOT 5}}

0
Page [[Adrian Vandenberg]] saved