Gebruiker:Edoderoobot/AWL

Uit Wikipedia, de vrije encyclopedie
import pywikibot
import sys
from urllib.request import urlopen
from bs4 import BeautifulSoup
from datetime import date

"""
Things to do:
*fix demonym, to auto-add correct categories
*int\roduce variables, first one to drive clean-up of non-used properties 
*add SparQL lists, alike Lysteria for lists of books/films/etc
*add switches : fill in a value depending on another value : ##switch#P21#Q6581097:voetballer#Q6581072:voetbalspeelster#else:speler##
*fix 'van/de/van de(r)' in a defaultsort
*units dependant on infobox (cm for athlete, nothing for soccer players)
"""

demonymList={
    'Q16':'Canadees','Q17':'Japans',
    'Q20':'Noors','Q21':'Engels','Q22':'Schots','Q25':'Welsh','Q26':'Noord-Iers','Q27':'Iers','Q28':'Hongaars','Q29':'Spaans',
    'Q30':'Amerikaans','Q31':'Belgisch','Q32':'Luxemburgs','Q33':'Fins','Q34':'Zweeds','Q35':'Deens','Q36':'Pools','Q37':'Litouws','Q38':'Italiaans','Q39':'Zwitsers',
    'Q40':'Oostenrijks','Q41':'Grieks','Q43':'Turks','Q45':'Portugees',
    'Q77':'Uruguayaans','Q79':'Egyptisch','Q96':'Mexicaans',
    'Q114':'Keniaans','Q115':'Ethiopisch','Q117':'Ghanees',
    'Q142':'Frans',
    'Q145':'Brits',
    'Q148':'Chinees',
    'Q155':'Braziliaans',
    'Q159':'Russisch',
    'Q183':'Duits','Q184':'Wit-Russisch','Q189':'IJslands',
    'Q191':'Estisch',
    'Q212':'Oekraïens','Q213':'Tsjechisch','Q214':'Slowaaks','Q215':'Sloveens','Q217':'Moldavisch','Q218':'Roemeens','Q219':'Bulgaars',
    'Q221':'Noord-Macedonisch','Q222':'Albanees','Q223':'Groenlands','Q224':'Kroatisch','Q225':'Bosnisch','Q227':'Azerbeidzjaans','Q228':'Andorrees','Q229':'Cypriotisch',
    'Q241':'Cubaans','Q242':'Belizaans',
    'Q252':'Indonesisch','Q258':'Zuid-Afrikaans',
    'Q398':'Bahreins','Q399':'Armeens',
    'Q408':'Australisch','Q414':'Argentijns',
    'Q664':'Nieuw-Zeelands',
    'Q730':'Surinaams','Q739':'Colombiaans','Q766':'Jamaicaans','Q778':'Bahamaans','Q781':'Antiguees','Q786':'Dominikaans',
    'Q801':'Israëlisch','Q884':'Zuid-Koreaans',
    'Q916':'Angolees','Q924':'Tanzaniaans','Q928':'Filipijns','Q953':'Zambiaans',
    'Q1009':'Kameroens','Q1028':'Marokkaans','Q1032':'Nigerees','Q1033':'Nigeriaans', 'Q1041':'Senegalees',
    'Q9676':'Brits', #eiland Man
    'Q15180':'Russisch','Q16635':'Guamees',
    'Q29999':'Nederlands',
    'Q33946':'Tsjecho-Slowaaks','Q36704':'Joegoslavisch',
            }

lng='nl'
site=pywikibot.Site(lng,'wikipedia')
repo=site.data_repository()
AWLversion='AWL20211103'
cleanup=True
fallback=['nl','en','de','fr']
SaR={'[[:Categorie:':'[[Categorie:',
     'Categorie:Antiguees olympisch deelnemer':'Categorie:Olympisch deelnemer uit Antigua en Barbuda',
     'uit [[Verenigde Staten':'uit de [[Verenigde Staten',
     'uit [[Verenigd K':'uit het [[Verenigd K',
     'Koninkrijk der Nederlanden':'Nederland',
     '(, ':'(',
     'Categorie:Dominicaans atleet':'Categorie:Atleet uit de Dominicaanse Republiek',
     'Categorie:Dominikaans olympisch deelnemer':'Categorie:Olympisch deelnemer uit de Dominicaanse Republiek',
     'op de Olympische Zomerspelen 1928]]':'op de Olympische Zomerspelen 1928|Olympische Zomerspelen van Amsterdam]] in 1928',
     'op de Olympische Zomerspelen 1932]]':'op de Olympische Zomerspelen 1932|Olympische Zomerspelen van Los Angeles]] in 1932',
     'op de Olympische Zomerspelen 1936]]':'op de Olympische Zomerspelen 1936|Olympische Zomerspelen van Berlijn]] in 1936',
     'op de Olympische Zomerspelen 1948]]':'op de Olympische Zomerspelen 1948|Olympische Zomerspelen van Londen]] in 1948',
     'op de Olympische Zomerspelen 1952]]':'op de Olympische Zomerspelen 1952|Olympische Zomerspelen van Helsinki]] in 1952',
     'op de Olympische Zomerspelen 1956]]':'op de Olympische Zomerspelen 1956|Olympische Zomerspelen van Melbourne]] in 1956',
     'op de Olympische Zomerspelen 1960]]':'op de Olympische Zomerspelen 1960|Olympische Zomerspelen van Rome]] in 1960',
     'op de Olympische Zomerspelen 1964]]':'op de Olympische Zomerspelen 1964|Olympische Zomerspelen van Tokio]] in 1964',
     'op de Olympische Zomerspelen 1968]]':'op de Olympische Zomerspelen 1968|Olympische Zomerspelen van Mexico]] in 1968',
     'op de Olympische Zomerspelen 1972]]':'op de Olympische Zomerspelen 1972|Olympische Zomerspelen van München]] in 1972',
     'op de Olympische Zomerspelen 1976]]':'op de Olympische Zomerspelen 1976|Olympische Zomerspelen van Montreal]] in 1976',
     'op de Olympische Zomerspelen 1980]]':'op de Olympische Zomerspelen 1980|Olympische Zomerspelen van Moskou]] in 1980',
     'op de Olympische Zomerspelen 1984]]':'op de Olympische Zomerspelen 1984|Olympische Zomerspelen van Los Angeles]] in 1984',
     'op de Olympische Zomerspelen 1988]]':'op de Olympische Zomerspelen 1988|Olympische Zomerspelen van Seoul]] in 1988',
     '[[Olympische Zomerspelen 1988]]':'Op de [[Olympische Zomerspelen 1988|Olympische Zomerspelen van Seoul]] in 1988',
     'op de Olympische Zomerspelen 1992]]':'op de Olympische Zomerspelen 1992|Olympische Zomerspelen van Barcelona]] in 1992',
     'op de Olympische Zomerspelen 1996]]':'op de Olympische Zomerspelen 1996|Olympische Zomerspelen van Atlanta]] in 1996',
     'op de Olympische Zomerspelen 2000]]':'op de Olympische Zomerspelen 2000|Olympische Zomerspelen van Sydney]] in 2000',
     'op de Olympische Zomerspelen 2004]]':'op de Olympische Zomerspelen 2004|Olympische Zomerspelen van Athene]] in 2004',
     'op de Olympische Zomerspelen 2008]]':'op de Olympische Zomerspelen 2008|Olympische Zomerspelen van Beijing]] in 2008',
     'op de Olympische Zomerspelen 2012]]':'op de Olympische Zomerspelen 2012|Olympische Zomerspelen van Londen]] in 2012',
     'op de Olympische Zomerspelen 2016]]':'op de Olympische Zomerspelen 2016|Olympische Zomerspelen van Rio de Janeiro]] in 2016',
     'op de Olympische Zomerspelen 2020]]':'op de Olympische Zomerspelen 2020|Olympische Zomerspelen van Tokio]] in 2021',
    }

eventconvert={
    'Javelin Throw':'speerwerpen',
    'Javelin Throw (700gr)':'speerwerpen (700gr)',
    'Long Jump':'verspringen',
    'Long Jump ind.':'verspringen ind.',
    'High Jump':'hoogspringen',
    'High Jump ind.':'hoogspringen ind.',
    'Pole Vault':'polsstokspringen',
    'Pole Vault ind.':'polsstokspringen ind.',
    'Decathlon':'tienkamp',
    'Decathlon - U20':'tienkamp - O20',
    'Decathlon - U18':'tienkamp - O18',
    'Heptathlon ind.':'zevenkamp ind.',
    'Heptathlon - U20 ind.':'zevenkamp - U20 ind',
    'Distance Medley':'afstandsestafette',
    'Distance Medley ind.':'afstandsestafette ind.',
    'Hammer Throw':'kogelslingeren',
    '100mH':'100 m horden',
    'Shot Put':'kogelstoten',
    'Shot Put ind.':'kogelstoten ind.',
    'Discus Throw':'discuswerpen',
             }
eventunit={'100m':'s','200m':'s','300m':'s','400m':'s','4x100':'s','Long Jump':'m','Pole Vault':'m','Decathlon':'p','High Jump':'m','100mH':'s',
           '100m ind.':'s','200m ind.':'s','300m ind.':'s','400m ind.':'s','4x100 ind.':'s','Long Jump ind.':'m','Pole Vault ind.':'m','High Jump ind.':'m',
          }
hdrconvert={'Event':'Onderdeel','Result':'Prestatie','Wind':'Wind','Venue':'Plaats','Date':'Datum'}

def monthname(month):
  nl_months=  {1:'januari',2:'februari',3:'maart',4:'april',5:'mei',6:'juni',7:'juli',8:'augustus',9:'september',10:'oktober',11:'november',12:'december'}
  papmonths= {1:'yanüari',2:'febrüari',3:'mart',4:'aprel',5:'mei',6:'yüni',7:'yüli',8:'ougùstùs',9:'sèptèmber',10:'oktober',11:'novèmber',12:'desèmber',}
  months={'nl':nl_months, 'pap':papmonths}
       
  return(months[lng][int(month)])

def get_formatter(wd,ppty):
  URLformat=''
  URLformatter=''  
  if not ppty in wd.claims: return(f'no url for {wd.title()}.{ppty}')  
  value=wd.claims[ppty][0].getTarget()
  if value==None: return('')  
  prop=pywikibot.PropertyPage(repo,ppty)  
  if not ('P1630' in prop.claims): return(f'no P1630 for {prop.title()}')  
  for c in prop.claims['P1630']:
    if (c.rank!='deprecated'):
      URLformat=c.getTarget()
    if (((URLformatter=='') or (c.rank=='preferred')) and (c.rank!='deprecated')):
      URLformatter=URLformat  
  return(URLformatter.replace('$1',value))

def getAthletePB(diamondID):
 url='https://www.diamondleague.com/athletes/%s.html'%diamondID
 f=urlopen(url)
 htmltext=f.read().decode('utf-8')
 soup=BeautifulSoup(htmltext)  
 pbtable=soup.find("table", attrs={"class":"personal-bests data"})
 pbevents=[th.get_text() for th in pbtable.find("tr").find_all("th")]   
 identifier='<!--leave for future auto-update [id:DL7156236875035]-->'

 pbresult = []
 for row in pbtable.find_all("tr")[1:]:
    dataset = dict(zip(pbevents, (td.get_text() for td in row.find_all("td"))))
    pbresult.append(dataset)    
    
 wikitable='==Persoonlijke records==\n'
 #outdoortable=f';Outdoor\n{{| class="wikitable"\n!Onderdeel\n!Prestatie\n!Plaats\n!Datum\n|-\n'
 #indoortable =f';Indoor\n{{| class="wikitable"\n!Onderdeel\n!Prestatie\n!Plaats\n!Datum\n|-\n'
 
 outdoortable=f';Outdoor\n{{| class="wikitable"'
 indoortable =f';Indoor\n{{| class="wikitable"'
 for event in pbevents:
   outdoortable += '\n!'+hdrconvert[event]
   indoortable  += '\n!'+hdrconvert[event]
 outdoortable += '\n|-\n'
 indoortable  += '\n|-\n'

    
 hasindoor=hasoutdoor=False
 for item in pbresult:
   itsout=itsin=False 
   for event in pbevents:
     if (event=='Event') and (item[event] in eventunit):
        unit=eventunit[item[event]]
     elif (event!='Result'):
        unit=''
     if event!='Event': 
        unitnow=unit   
     else:
        unitnow=''
     if (item['Event'].find('ind.')==-1): 
      if item[event] in eventconvert:
        item[event] = eventconvert[item[event]]
      outdoortable+='| '+item[event]+unitnow+'\n'
      hasoutdoor=itsout=True
     else: 
      if (item[event] in eventconvert):
        item[event]=eventconvert[item[event]]  
      indoortable+='| '+item[event]+unitnow+'\n'
      hasindoor=itsin=True
   if (itsout): outdoortable+='|-\n'
   if (itsin): indoortable+='|-\n'   
 month=date.today().strftime('%m')   
 monthstr=monthname(month)
 #monthstr=date.today().strftime('%B')
 yearstr =date.today().strftime('%Y')
 if hasindoor or hasoutdoor:
   if hasoutdoor:
     wikitable += outdoortable + '|}\n' 
   if hasindoor:     
        wikitable += indoortable + '|}\n'
   wikitable += f'bijgewerkt {monthstr}-{yearstr}<ref>[{url} Diamondleague]––profiel</ref>{identifier}\n'
 return(wikitable)

def findifs(wd,txt):
    """
    Find all ##if:P1234# constructions
    if P1234 is a claim, the line will stay, else it will be deleted
    """
    p=txt.find('##if:')
    while (p>0):
      end=p+2
      while txt[end:end+1]!='#':
        end+=1
      property=txt[p+5:end]  
      if property in wd.claims:
         txt=txt[:p]+txt[end+1:]
      else:
         while txt[end:end+1]!='\n': #find end of line
            end+=1
         txt=txt[:p]+txt[end+1:]
      p=txt.find('##if:')        
    
    """
    Find all #profiel:Pxxx# constructions
    if P1234 is a valid claim, the line will be filled out based on the URL-formtter of P1234
    """
    p=txt.find('##profiel:')
    while (p>0):
      end=p+2
      while txt[end:end+1]!='#':
        end+=1
      property=txt[p+10:end]  
      if property in wd.claims:
         txt=txt[:p]+txt[end+1:].replace('##format#',get_formatter(wd,property),1)
      else:
         while txt[end:end+1]!='\n': #find end of line
           end+=1
         txt=txt[:p]+txt[end+1:]
      p=txt.find('##profiel:')        
    
    """
    Find all ##loop:Pxxx# constructions
    if P1234 is a valid claim, it will add all linked claims as wikitext-link
    """
    p=txt.find('##loop:')
    while (p>0):
      end=p+2
      while txt[end:end+1]!='#':
        end+=1
      property=txt[p+7:end]
      if property in wd.claims:
        looptxt=''
        for x in range(0,len(wd.claims[property])):
            looptxt+=f'{wd_value(wd,property,True,x)}\n'
        txt=txt[:p]+looptxt+txt[end+1:]
      else:
        while txt[end:end+1]!='\n': #find end of line
          end+=1
        txt=txt[:p]+txt[end+1:]
      p=txt.find('##loop:')  
    return(txt)
    
def demonym(wd,lng):
    
  #return('')  
  if 'P27' in wd.claims:
    countryID=wd.claims['P27'][0].getTarget().title()
    if countryID in demonymList:
        return demonymList[countryID]
    land_bestaat_niet(countryID/0)
    country=pywikibot.ItemPage(repo,countryID)
    country.get(get_redirect=True)
    if ('P1549' in country.claims):
      dmn=country.claims['P1549']
      for dmnclaim in dmn:
        dmnclaim.get()    
        if dmnclaim.has_qualifier:
          qlf=dmnclaim.qualifiers
          if ('P518') in qlf:
            vtod=qlf['P518'][0].getTarget().title()
            if vtod=='Q47088290':  #mannelijk enkelvoud
              pass
            else:
              for x in dir(dmnclaim):
                print(x)
              print(f'claim={dmnclaim}')
              #print(f'vtod={vtod}')
          else:
            pass
            #print(f'qlf={qlf}')
        else:
          print(dmnclaim)  
    return('xXx')
  return('-nd-')

def find_properties(txt):
    i=0
    end=0
    while(i<len(txt)):
      if txt[i:i+2]=='<P':
        end=i
        while txt[end:end+1]!='>':
          end+=1
        yield(txt[i+1:end],'<')  
        i=end
      if txt[i:i+2]=='[P':
        end=i
        while txt[end:end+1]!=']':
          end+=1
        yield(txt[i+1:end],'[')  
        i=end
      if txt[i:i+2]=='!P':
        end=i
        while txt[end:end+1]!='!':
          end+=1
        yield(txt[i+1:end],'!')  
        i=end
      i+=1
      if txt[i:i+7]=='<label>':
        yield('label','')
        i+=7
      if txt[i:i+10]=='<demoniem>':
        yield('demoniem','')
        i+=10
      if txt[i:i+11]=='<templates>':
        yield('templates','')
        i+=11
      if txt[i:i+9]=='<inlinks>':
        yield('inlinks','')
        i+=9
      if txt[i:i+9]=='<sources>':
        yield('sources','')
        i+=9
      if txt[i:i+9]=='<diamond>':
        yield('diamond','')
        i+=9
      if txt[i:i+6]=='##var:':
        i=i+6
        end=i
        while txt[end:end+1]!=':':
          end+=1
        print(f'-var-: <{txt[i:end]}>, {i},{end}')
        yield(txt[i:end],'')    

def fill_in(txt,find,replace):
    return(txt.replace(find,replace,-1))
    
def getUnit(value):
    try:
      wdUnit=value.unit[value.unit.find('Q'):]
      unit=pywikibot.ItemPage(repo,wdUnit)
      unit.get(get_redirect=True)
      return(unit.labels[lng])  
    except Exception as e: 
        print(e)

def wd_value(wd,property,isLinked=False,index=0):
    
  image=pywikibot.page.FilePage(site,'image.png')  
    
  if property in wd.claims:
      value=wd.claims[property][index].getTarget()
      if value==None:
          return('none')
      if (type(value)==type(pywikibot.ItemPage(repo,'Q5'))):
        valuerec=pywikibot.ItemPage(repo,value.title())
        valuerec.get(get_redirect=True)
        if not lng in valuerec.labels:
            print(f'label missing in {valuerec.title()}.{property}')
            error('')
        if ((isLinked) and (lng+'wiki' in valuerec.sitelinks)):
          lbl=valuerec.labels[lng]
          lnk=valuerec.sitelinks[lng+'wiki'].title
          if (lbl[0].lower()==lnk[0].lower()) and (lbl[1:]==lnk[1:]):
            return(f'[[{lnk}]]')
          else:
            return(f'[[{lnk}|{lbl}]]')    
        else:
          return(valuerec.labels[lng])  
      elif (type(value)==type(pywikibot.WbTime(1,1,1))):
        if value.precision==11:
          return(str(value.day)+' '+monthname(value.month)+' '+str(value.year))
        elif value.precision==9:
          return(str(value.year))
        elif value.precision==7: #precision like 20th century : nothing valueble to return
          return('')
        return(f'date-time: precision={value.precision}')
      elif (type(value)==type('str')):
        return(value)
      elif (type(value)==type(pywikibot.WbMonolingualText('nl','nl'))):
          return(value.text)  
      elif (type(value)==type(pywikibot.WbQuantity(0,site=site))):
        if value.unit:
          return(f'{str(value.amount)} {getUnit(value)}')
        return(str(value.amount))
      elif (type(value)==type(pywikibot.page.FilePage(site,'image.png'))): #P18 image on Commons
         return(value.title()[5:])
    
    
      else:
        print(f'unknown type: {type(value)}')
        return('else')
      return value
  elif property=='label':
    try:
      return(wd.labels[lng])  
    except:
      pass
  elif property=='demoniem':
     return(demonym(wd,lng))
  elif property=='templates':
     return(whatlinkshere(lng,wd.labels[lng],[10])) #actually wd.links[wiki+'lng'] 
  elif property=='inlinks':
     return(whatlinkshere(lng,wd.labels[lng],[0]))  #but lemma does not exist yet
  elif property=='sources':
     return(getSources(wd)) 
  elif property=='diamond':
     if ('P3923' in wd.claims):    
       return(getAthletePB(wd.claims['P3923'][0].getTarget()))   
     return('')
  else:
    if (cleanup):
      return('') 
    else:
      return('<'+property+'>')
  return('')
 
def getSourceURLs(wd):
 urls=[]
 for c in wd.claims: 
  claimlist=wd.claims[c]
  for claim in claimlist:
    sources=claim.getSources()
    if sources!=[]: 
      for sourcelist in sources:  
       if ('P854' in sourcelist): 
        for source in sourcelist['P854']:
          url=source.getTarget()
          if (not(url in urls)):
              urls.append(url)
 return(urls)         
  
def getSources(wd):
 sourcelist=''
 count=0
 for sourceURL in getSourceURLs(wd):
   count+=1           
   sourcelist=sourcelist+f'<ref>[{sourceURL} bron {count}]––</ref>\n'         
 return(sourcelist)           
    
def whatlinkshere(lng,item,namespaces):
  site=pywikibot.Site(lng,'wikipedia')
  page=pywikibot.Page(site,item)
  result=''
  for found in page.getReferences(namespaces=namespaces):
    start=found.title().find(':')
    if (10 in namespaces):
      result+='{{'+found.title()[start+1:]+'}}\n'
    else:
      result+='[['+found.title()[start+1:]+']]\n'
  return result

def readTemplate(name):
    site=pywikibot.Site(lng,'wikipedia')
    page=pywikibot.Page(site,'gebruiker:Edoderoo/template/'+name)
    try:
      #print('1')  
      glbPage=pywikibot.Page(site,'gebruiker:Edoderoo/template/global')  
      #print('22')  
      globaltxt=glbPage.text  
      #print('333')  
    except:
      globaltxt=''
      print('gebruiker:Edoderoo/template/global not found')
    if (page.exists()):
      return(page.text.replace('<global>',globaltxt))
    else:
      return(name+'does not exist!')  
    

def getTemplate(wd):
  if 'P106' in wd.claims:
    for beroep in wd.claims['P106']:
      beroepID=beroep.getTarget().title()
      if (False): pass
      elif beroepID=='Q2309784' : return readTemplate('wielrenner')
      elif beroepID=='Q15117395': return readTemplate('wielrenner')
      elif beroepID=='Q15117415': return readTemplate('wielrenner')
      elif beroepID=='Q19799599': return readTemplate('wielrenner')
      elif beroepID=='Q937857'  : return readTemplate('voetballer')
      elif beroepID=='Q11513337': return readTemplate('atleet')
      elif beroepID=='Q4009406' : return readTemplate('atleet')
      elif beroepID=='Q13381689': return readTemplate('atleet')
      elif beroepID=='Q13724897': return readTemplate('atleet')
      elif beroepID=='Q15306067': return readTemplate('sporter') #triatleet
      elif beroepID=='Q13381753': return readTemplate('atleet')
      elif beroepID=='Q21141408': return readTemplate('atleet')
      elif beroepID=='Q15972912': return readTemplate('sporter') #moderne vijfkamp
      elif beroepID=='Q482980'  : return readTemplate('auteur')
      elif beroepID=='Q36180'   : return readTemplate('auteur')
      elif beroepID=='Q4853732' : return readTemplate('auteur')
      elif beroepID=='Q33999'   : return readTemplate('acteur')
      elif beroepID=='Q10800557': return readTemplate('acteur')
      elif beroepID=='Q177220'  : return readTemplate('artiest')
      elif beroepID=='Q82955'   : return readTemplate('politicus')
      elif beroepID=='Q10866633': return readTemplate('schaatser')
      elif beroepID=='Q18200514': return readTemplate('schaatser')
      elif beroepID=='Q10843263': return readTemplate('hockeyspeler')
      elif beroepID=='Q10843402': return readTemplate('zwemmer')
      elif beroepID=='Q13141064': return readTemplate('badmintonner')  
      elif beroepID=='Q10833314': return readTemplate('tennisser')
      elif beroepID=='Q13381863': return readTemplate('schermer')
      elif beroepID=='Q11774891': return readTemplate('ijshockeyer')
      elif beroepID=='Q17516936': return readTemplate('curlingspeler')
      elif beroepID=='Q859528'  : return readTemplate('scheidsrechter')
      elif beroepID=='Q3665646' : return readTemplate('basketballer')  
      elif beroepID=='Q15117302': return readTemplate('volleyballer')
      elif beroepID=='Q12840545': return readTemplate('handballer')
      elif beroepID=='Q13382519': return readTemplate('tafeltennisser')
      elif beroepID=='Q10873124': return readTemplate('schaker')
      elif beroepID=='Q13382608': return readTemplate('wintersporter') 
      elif beroepID=='Q4270517' : return readTemplate('wintersporter')
      elif beroepID=='Q4144610' : return readTemplate('wintersporter')
      elif beroepID=='Q13382981': return readTemplate('sporter') #rodelaar
      elif beroepID=='Q16029547': return readTemplate('sporter') #biatleet
      elif beroepID=='Q6665249' : return readTemplate('sporter') 
    print(f'beroep not found: {beroep}')
  if 'P31' in wd.claims:
    for is_a in wd.claims['P31']:
      its_a=is_a.getTarget().title()
      if   its_a=='Q8502': return readTemplate('berg')
      elif its_a=='Q4022': return readTemplate('rivier')  
      elif its_a=='Q23397': return readTemplate('meer')
      elif its_a=='Q1134686': return readTemplate('frazione')  
      elif its_a=='Q16917': return readTemplate('ziekenhuis')
      elif its_a=='': return readTemplate('error') 
      else:
        print('Unknown %s', its_a)
        error('')
  return wd.title()

def standardReplace(input):
    output=input
    for fnd in SaR:
      output=output.replace(fnd,SaR[fnd])  
    return(output)

def maak_item(qid):
  wd=pywikibot.ItemPage(repo,qid)
  wd.get(get_redirect=True)
  txt=getTemplate(wd)
  if not(lng+'wiki' in wd.sitelinks):
    if not lng in wd.labels:
      error('Add a label first, it will become the title')  
    for p,isLinked in find_properties(txt): 
      value=wd_value(wd,p,isLinked=='[')
      if isLinked=='[':
        txt=fill_in(txt,'['+p+']',value)    
      elif isLinked=='<':
        txt=fill_in(txt,'<'+p+'>',value)
      elif isLinked=='!':
        txt=fill_in(txt,'!'+p+'!',value)
      elif p in ['label','demoniem','templates','inlinks','sources','diamond']:
        txt=fill_in(txt,f'<{p}>',value)
      else:      
        sys.exit(f'unknown: {isLinked}{p}{isLinked}')
        
    txt=txt+f'<!--{AWLversion}-->\n'    
    txt=txt+'<!--'+wd.title()+'-->'
    
    return(standardReplace(findifs(wd,txt)))
  else:
    return('') #already exists for this language
    


####Red Flames - Belgisch nationaal elftal
print(maak_item('Q98070069')) #Hannah Eurlings