import pywikibot
from pywikibot import pagegenerators
import mwparserfromhell
from mwparserfromhell.nodes import Template

useSite='nl'
useCategory={'nl':'Categorie:Tennisser naar nationaliteit'}
useTarget={'nl':'Gebruiker:Edoderoo/Tennis-stats','de':'Benutzer:Edoderoo/Tennis-stats','en':'User:Edoderoo/Tennis-stats'}

intro={'nl':'Deze pagina is automatisch aangemaakt. Wijzig het niet handmatig.','de':'','en':'This page is created automatically by a script. Please do not change it manually.','fr':''}
infobox_title={'nl':'Infobox tennisspeler','de':'Infobox Tennisspieler','en':'Infobox tennis biography','fr':'Infobox Joueur de tennis'}
infobox_singles={'nl':'enkelrecord','de':'einzelbilanz','en':'singlesrecord','fr':''}
infobox_prize={'nl':'prijzengeld', 'de':'preisgeld', 'en':'careerprizemoney', 'fr':'gains en tournois'}
infobox_doubles={'nl':'dubbelrecord','de':'doppelbilanz','en':'doublesrecord','fr':''}
infobox_image={'nl':'afbeelding','de':'bild','en':'image','fr':'image'}
table_start='{| class="wikitable sortable"\n|-\n! Type !! Item !! diff !! country \n|-'
table_end='\n|}\n'
max_man=99
max_man_dollar=99000
max_woman=199
max_woman_dollar=7800

def smallest(x):
  smallval=x[0]
  for y in x:
    if y<smallval:
      smallval=y
  return smallval

def getCategory(page,text2find=None):
  catfound = None
  for c in page.categories():
    if not(text2find==None):
      if ((c.title().upper().find(text2find.upper())) >= 0):
        catfound = c.title()[10:]
        break
    else: 
      catfound=c.title()[10:] 
      break
    
  return catfound

def getTemplate(page,template):                #find one template on a page
  wikicode=mwparserfromhell.parse(page.text)     
  templates=wikicode.filter_templates()
  mytemplates = [x for x in templates if x.name.matches(template)]
  if (len(mytemplates)>0):
    for returntemplate in mytemplates:
      yield  returntemplate                    #return template we searched for  

def get_int_from_str(mystr):
  numbers='0123456789'
  ok=numbers+'.,'
  start=0
  while (start<len(mystr)) and (not(mystr[start] in numbers)):
    start+=1
  stop=start
  result=''
  while (stop<len(mystr)) and (mystr[stop] in ok):
    if (mystr[stop] in numbers):
      result+=mystr[stop]
    stop+=1
  if (result==''):
    return 0
  return int(result)

def strip_from_till(mystr, fromstr, tillstr):
  start=mystr.find(fromstr)+len(fromstr)
  end=mystr.find(tillstr)
  if (start<end):
    return mystr[start:end]
  return mystr

def strip_stuff_from_str(mystr):
  mystr=mystr.lower().replace('[[amerikaanse dollar|us$]]','').replace('[[amerikaanse dollar|$]]','')
  mystr=mystr.replace('[[US$]]','')
  mystr=strip_from_till(mystr,'<!--','-->')
  mystr=strip_from_till(mystr,'<ref>','</ref>')
  return mystr.strip()  

def get_values(lng,pagetxt):
  dollars_value=-1
  image_found=False
  for onetemplate in getTemplate(pagetxt,infobox_title[lng]):
    for oneparam in onetemplate.params:
      paramname=oneparam.name.strip().lower()
      if (paramname in [infobox_prize[lng],infobox_singles[lng],infobox_doubles[lng],infobox_image[lng]]):
        thisvalue = strip_stuff_from_str(oneparam.value)
        if (paramname==infobox_image[lng]):
          image_found=image_found or (thisvalue!='')
        if (paramname==infobox_prize[lng]):
          if (thisvalue.find('p2121') != -1): #not in use right now on de-wiki, but let's hope they mature ;-)
            dollars_value=0
          else:
            dollars_value = get_int_from_str(thisvalue)
  return dollars_value, image_found

def getUICcode_fromPerson(wd):
  if ('P27' in wd.claims):
    con=wd.claims['P27'][0].getTarget()
    con.get(get_redirect=True)
    if ('P2981' in con.claims):
      uic=con.claims['P2981'][0].getTarget()
      return(uic)
  return('')

def all_from_cat(thissite,thiscat):

 site=pywikibot.Site(thissite)
 cat = pywikibot.Category(site,thiscat)
 gen = pagegenerators.CategorizedPageGenerator(cat,12)
 wdsite=pywikibot.Site('wikidata','wikidata')
 repo=wdsite.data_repository()
 total_women=found_woman=total_men=found_man=0
 
 en_site=pywikibot.Site('en')
 de_site=pywikibot.Site('de') 
 fr_site=pywikibot.Site('fr')
 mantxt=femtxt=''
 
 for src_page in gen: 
   if ('wikibase_item' in src_page.properties()):
     man=woman=False
     wd_dd = -1.11
     de_dollars_value=en_dollars_value=fr_dollars_value=0
     de_image=en_image=fr_image=False
     indicator='$'
     wd=src_page.data_item()
     wd.get(get_redirect=True)
     if ('P597' in wd.claims):
       total_women+=1
       woman = True
     if ('P536' in wd.claims):
       total_men+=1
       man = True
     
     if (('P597' in wd.claims) and (found_woman<max_woman)) or (('P536' in wd.claims) and (found_man<max_man)): #skip if not WTA-id or ATP-id defined 
       male=female=False
       if ('P21' in wd.claims):
         sex=wd.claims.get('P21')[0].getTarget()
         if (sex.title()=='Q6581072'): 
           indicator='$$$'
           female=True
         if (sex.title()=='Q6581097'): 
           indicator='$$'
           male=True
       if ('P2121' in wd.claims):
         wd_pr=wd.claims.get('P2121')[0].getTarget()
         if (isinstance(wd_pr,pywikibot.WbQuantity)):
           wd_dd = wd_pr.amount
         else:
           wd_dd = -2
       if ('dewiki' in wd.sitelinks): 
         de_page=pywikibot.Page(de_site, wd.sitelinks['dewiki'])
         de_dollars_value, de_image=get_values('de',de_page)
       nl_dollars_value, nl_image =get_values(useSite,src_page)  
       if ('enwiki' in wd.sitelinks):
         en_page=pywikibot.Page(en_site, wd.sitelinks['enwiki'])
         en_dollars_value, en_image=get_values('en',en_page)
       if ('frwiki' in wd.sitelinks):
         fr_page=pywikibot.Page(fr_site, wd.sitelinks['frwiki'])
         fr_dollars_value, fr_image=get_values('fr',fr_page);
       if (src_page.text.lower().find('[[amerikaanse doll')>0):
         indicator += '!'
       if (not nl_image) and ((de_image) or (en_image) or (('P18') in wd.claims)):
         indicator += 'i'  #other sites might have a useful image
       
       ax=(wd_dd == -1.11)
       fbx=((not(nl_dollars_value==wd_dd)) and (not(nl_dollars_value>=0)) and(nl_dollars_value!=-1) and (woman))
       mbx=((not(nl_dollars_value==wd_dd)) and (not(nl_dollars_value>=0)) and(nl_dollars_value!=-1) and (man))
       dex=( (((de_dollars_value>wd_dd+max_woman_dollar) and woman) or (de_dollars_value>wd_dd+max_man_dollar)) and (de_dollars_value>0)) 
       enx=( (((en_dollars_value>wd_dd+max_woman_dollar) and woman) or (en_dollars_value>wd_dd+max_man_dollar)) and (en_dollars_value>0))
       frx=( (((fr_dollars_value>wd_dd+max_woman_dollar) and woman) or (fr_dollars_value>wd_dd+max_man_dollar)) and (fr_dollars_value>0))
       if (  ax \
          or fbx or mbx \
          or dex \
          or enx \
          or frx
          ):
         diffde=wd_dd-de_dollars_value
         diffen=wd_dd-en_dollars_value
         difffr=wd_dd-fr_dollars_value
         
         thistxt = f'|-\n|{indicator}||[[:d:{wd.title()}]]||{abs(smallest((diffde,diffen,difffr)))}||{getUICcode_fromPerson(wd)}\n'
         if (male) :
           mantxt += thistxt
           found_man+=1
         if (female) :
           femtxt += thistxt
           found_woman+=1
         #print('man: %d – women: %d' % (found_man, found_woman))
         print('%s'%thistxt)
       else:
         #print('\-\n|%s||[[:d:%9s]]||[%9d]||nl||[%9d]||==||{%8d}||/||de||[%9d]||{%8d}\n' %(indicator,wd.title(),wd_dd,nl_dollars_value,wd_dd-nl_dollars_value,de_dollars_value,de_dollars_value-wd_dd))
         pass

 wikitext = intro[useSite]+'\n\n'+table_start+femtxt+table_end+'\n\n'+table_start+mantxt+table_end+'\n\nMan..:%d\nWomen: %d\n' % (total_men,total_women)

 if (True):
   print('%s' % wikitext)
   pywikibot.Page(pywikibot.Site(useSite), useTarget[useSite]).put(wikitext, summary='Update tennis statistics suggestions') #Save page  

print('Started') 
all_from_cat(useSite,useCategory[useSite])
print('Finished')
|-
|$$$||[[:d:Q17523802]]||{   50875}||00001

|-
|$$||[[:d:Q17660516]]||{   50365}||00001

|-
|$$||[[:d:   Q53566]]||{   99250}||00001

|-
|$$||[[:d:   Q53569]]||{  161400}||00001

|-
|$$$||[[:d:Q18679122]]||{   26430}||00001

|-
|$$||[[:d: Q4823160]]||{   52730}||00011

|-
|$$||[[:d: Q1187478]]||{   63637}||00011

|-
|$$||[[:d:Q17612636]]||{   70234}||00010

|-
|$$||[[:d:   Q54538]]||{   58945}||00001

|-
|$$||[[:d:  Q555660]]||{  143400}||00101

|-
|$$||[[:d:   Q25623]]||{   50404}||00011

|-
|$$||[[:d:   Q54663]]||{   73923}||00011

|-
|$$$||[[:d:   Q54670]]||{   37875}||00001

|-
|$$||[[:d:Q17305299]]||{   65230}||00001

|-
|$$$||[[:d:   Q11459]]||{   48775}||00001

|-
|$$||[[:d: Q2316401]]||{   82935}||00100

|-
|$$||[[:d:   Q33249]]||{   71275}||00001

|-
|$$||[[:d:  Q336862]]||{   56820}||00001

|-
|$$||[[:d: Q5274812]]||{   94880}||00001

|-
|$$||[[:d: Q3183203]]||{   50617}||00010

|-
|$$||[[:d: Q3462853]]||{  175824}||00011

|-
|$$||[[:d:  Q515677]]||{  172633}||00011

|-
|$$||[[:d: Q3784554]]||{   72750}||00001

|-
|$$||[[:d: Q6162896]]||{  154175}||00010

|-
|$$||[[:d: Q2152388]]||{   95235}||00011

|-
|$$||[[:d:Q22958938]]||{   75385}||00001

|-
|$$i||[[:d:Q30143529]]||{   50305}||00011

|-
|$$||[[:d:Q16219277]]||{   50670}||00001

|-
|$$||[[:d:  Q288326]]||{   82908}||00011

|-
|$$$||[[:d: Q2712407]]||{   26430}||00001

|-
|$$||[[:d:  Q718187]]||{   59043}||00001

|-
|$$||[[:d:  Q164531]]||{  104573}||00011

|-
|$$||[[:d:   Q19406]]||{   86548}||00001

|-
|$$||[[:d: Q2158099]]||{   50837}||00001

|-
|$$||[[:d:  Q439942]]||{  196331}||00011

|-
|$$||[[:d: Q6451141]]||{   99250}||00001

|-
|$$||[[:d:  Q169389]]||{   57110}||00001

|-
|$$$||[[:d:  Q770789]]||{   55860}||00001

|-
|$$||[[:d:Q23668736]]||{  109585}||00011

|-
|$$||[[:d:  Q317820]]||{   70900}||00111

|-
|$$||[[:d: Q1943147]]||{   74447}||00011

|-
|$$||[[:d:  Q440531]]||{   54078}||00011

|-
|$$||[[:d:Q20979382]]||{  118932}||00001

|-
|$$$||[[:d:  Q197291]]||{   34475}||00001

|-
|$$$||[[:d:  Q197634]]||{   16425}||00001

|-
|$$||[[:d:  Q921488]]||{   65228}||00001

|-
|$$||[[:d: Q1355458]]||{   50005}||00001

|-
|$$||[[:d:  Q552349]]||{  115095}||00001

|-
|$$||[[:d:  Q207084]]||{   89115}||00111

|-
|$$||[[:d:  Q714047]]||{   54514}||00001

|-
|$$||[[:d:   Q77164]]||{   50530}||00111

|-
|$$||[[:d:   Q60717]]||{   54421}||00111

|-
|$$||[[:d:   Q77159]]||{   63373}||00111

|-
|$$||[[:d:   Q91615]]||{  169469}||00011

|-
|$$||[[:d:   Q77149]]||{  155207}||00011

|-
|$$||[[:d:Q17364412]]||{  176494}||00011

|-
|$$||[[:d:Q29559367]]||{   72191}||00110

|-
|$$||[[:d: Q1681537]]||{  106235}||00011

|-
|$$i||[[:d:Q13990552]]||{   56820}||00001

|-
|$$||[[:d:   Q13538]]||{   92825}||00001

|-
|$$||[[:d:Q24228674]]||{   55122}||00010

|-
|$$||[[:d:  Q176577]]||{  163024}||00101

|-
|$$$||[[:d:  Q258877]]||{   34475}||00001

|-
|$$||[[:d: Q2093033]]||{  104305}||00001

|-
|$$||[[:d:Q49562573]]||{   68248}||00010

|-
|$$||[[:d:  Q373522]]||{  169402}||00011

|-
|$$||[[:d:Q13403768]]||{   53136}||00001

|-
|$$||[[:d:  Q274441]]||{  125578}||00101

|-
|$$||[[:d:  Q212833]]||{   74242}||00001

|-
|$$||[[:d:  Q192661]]||{   68649}||00011

|-
|$$||[[:d:Q16297666]]||{  120830}||00001

|-
|$$$||[[:d:Q16399655]]||{   20767}||00010

|-
|$$||[[:d:  Q649333]]||{  170689}||00011

|-
|$$||[[:d:  Q511986]]||{   77720}||00011

|-
|$$||[[:d:Q15759429]]||{   74862}||00011

|-
|$$||[[:d: Q5284058]]||{   69781}||00011

|-
|$$||[[:d:Q29918446]]||{  195161}||00101

|-
|$$||[[:d:  Q315970]]||{   53215}||00001

|-
|$$||[[:d:Q13360044]]||{   51840}||00001

|-
|$$||[[:d:  Q251980]]||{   82360}||00011

|-
|$$!||[[:d:  Q708313]]||{   93908}||00001

|-
|$$||[[:d:  Q319572]]||{   99916}||00011

|-
|$$||[[:d:Q24061220]]||{   70605}||00010

|-
|$$||[[:d:Q15714673]]||{  179609}||00011

|-
|$$||[[:d:  Q708345]]||{   91065}||00001

|-
|$$||[[:d:Q30528312]]||{  106503}||00001

|-
|$$||[[:d:  Q311222]]||{  210592}||00011

|-
|$$||[[:d:Q16735453]]||{  225856}||00001

|-
|$$||[[:d:  Q245241]]||{   69590}||00001

|-
|$$||[[:d:Q14905846]]||{  182367}||00001

|-
|$$||[[:d:  Q324515]]||{   63576}||00001

|-
|$$||[[:d:  Q295483]]||{   91205}||00001

|-
|$$||[[:d: Q7035585]]||{  228645}||00001

|-
|$$||[[:d: Q1588571]]||{  163687}||00011

|-
|$$||[[:d: Q3502012]]||{   78201}||00001

|-
|$$||[[:d:  Q295866]]||{  135720}||00011

|-
|$$$||[[:d: Q5551564]]||{   48775}||00001

|-
|$$$||[[:d:  Q232445]]||{   56820}||00001

|-
|$$||[[:d:  Q441037]]||{   53025}||00001

|-
|$$||[[:d:  Q527839]]||{   70119}||00101

|-
|$$||[[:d: Q6835083]]||{  179303}||00011

|-
|$$||[[:d:Q18810082]]||{  106406}||00011

|-
|$$||[[:d:  Q211636]]||{  103690}||00001

|-
|$$$||[[:d:  Q289378]]||{   48775}||00001

|-
|$$||[[:d:  Q317961]]||{  116204}||00011

|-
|$$||[[:d:  Q441027]]||{   93107}||00001

|-
|$$||[[:d:  Q409547]]||{   63503}||00001

|-
|$$||[[:d:Q18927958]]||{  182000}||00001

|-
|$$||[[:d:  Q345626]]||{  226480}||00011

|-
|$$||[[:d: Q1338865]]||{   66955}||00001

|-
|$$$||[[:d: Q2439034]]||{   34475}||00001

|-
|$$||[[:d:  Q523725]]||{   58521}||00001

|-
|$$||[[:d:  Q457011]]||{  118550}||00001

|-
|$$$||[[:d:Q17144642]]||{   26430}||00001

|-
|$$$||[[:d:  Q211802]]||{   26430}||00001

|-
|$$$||[[:d:Q20968624]]||{   16425}||00001

|-
|$$$||[[:d:  Q232566]]||{   54930}||00001

|-
|$$$||[[:d:  Q230353]]||{   54930}||00001

|-
|$$$||[[:d:   Q10118]]||{   34475}||00001

|-
|$$$||[[:d: Q4725560]]||{   26430}||00001

Deze pagina is automatisch aangemaakt. Wijzig het niet handmatig.

{| class="wikitable sortable"
|-
! Type !! Item !! diff !! binary 
|-|-
|$$$||[[:d:Q17523802]]||{   50875}||00001
|-
|$$$||[[:d:Q18679122]]||{   26430}||00001
|-
|$$$||[[:d:   Q54670]]||{   37875}||00001
|-
|$$$||[[:d:   Q11459]]||{   48775}||00001
|-
|$$$||[[:d: Q2712407]]||{   26430}||00001
|-
|$$$||[[:d:  Q770789]]||{   55860}||00001
|-
|$$$||[[:d:  Q197291]]||{   34475}||00001
|-
|$$$||[[:d:  Q197634]]||{   16425}||00001
|-
|$$$||[[:d:  Q258877]]||{   34475}||00001
|-
|$$$||[[:d:Q16399655]]||{   20767}||00010
|-
|$$$||[[:d: Q5551564]]||{   48775}||00001
|-
|$$$||[[:d:  Q232445]]||{   56820}||00001
|-
|$$$||[[:d:  Q289378]]||{   48775}||00001
|-
|$$$||[[:d: Q2439034]]||{   34475}||00001
|-
|$$$||[[:d:Q17144642]]||{   26430}||00001
|-
|$$$||[[:d:  Q211802]]||{   26430}||00001
|-
|$$$||[[:d:Q20968624]]||{   16425}||00001
|-
|$$$||[[:d:  Q232566]]||{   54930}||00001
|-
|$$$||[[:d:  Q230353]]||{   54930}||00001
|-
|$$$||[[:d:   Q10118]]||{   34475}||00001
|-
|$$$||[[:d: Q4725560]]||{   26430}||00001

|}


{| class="wikitable sortable"
|-
! Type !! Item !! diff !! binary 
|-|-
|$$||[[:d:Q17660516]]||{   50365}||00001
|-
|$$||[[:d:   Q53566]]||{   99250}||00001
|-
|$$||[[:d:   Q53569]]||{  161400}||00001
|-
|$$||[[:d: Q4823160]]||{   52730}||00011
|-
|$$||[[:d: Q1187478]]||{   63637}||00011
|-
|$$||[[:d:Q17612636]]||{   70234}||00010
|-
|$$||[[:d:   Q54538]]||{   58945}||00001
|-
|$$||[[:d:  Q555660]]||{  143400}||00101
|-
|$$||[[:d:   Q25623]]||{   50404}||00011
|-
|$$||[[:d:   Q54663]]||{   73923}||00011
|-
|$$||[[:d:Q17305299]]||{   65230}||00001
|-
|$$||[[:d: Q2316401]]||{   82935}||00100
|-
|$$||[[:d:   Q33249]]||{   71275}||00001
|-
|$$||[[:d:  Q336862]]||{   56820}||00001
|-
|$$||[[:d: Q5274812]]||{   94880}||00001
|-
|$$||[[:d: Q3183203]]||{   50617}||00010
|-
|$$||[[:d: Q3462853]]||{  175824}||00011
|-
|$$||[[:d:  Q515677]]||{  172633}||00011
|-
|$$||[[:d: Q3784554]]||{   72750}||00001
|-
|$$||[[:d: Q6162896]]||{  154175}||00010
|-
|$$||[[:d: Q2152388]]||{   95235}||00011
|-
|$$||[[:d:Q22958938]]||{   75385}||00001
|-
|$$i||[[:d:Q30143529]]||{   50305}||00011
|-
|$$||[[:d:Q16219277]]||{   50670}||00001
|-
|$$||[[:d:  Q288326]]||{   82908}||00011
|-
|$$||[[:d:  Q718187]]||{   59043}||00001
|-
|$$||[[:d:  Q164531]]||{  104573}||00011
|-
|$$||[[:d:   Q19406]]||{   86548}||00001
|-
|$$||[[:d: Q2158099]]||{   50837}||00001
|-
|$$||[[:d:  Q439942]]||{  196331}||00011
|-
|$$||[[:d: Q6451141]]||{   99250}||00001
|-
|$$||[[:d:  Q169389]]||{   57110}||00001
|-
|$$||[[:d:Q23668736]]||{  109585}||00011
|-
|$$||[[:d:  Q317820]]||{   70900}||00111
|-
|$$||[[:d: Q1943147]]||{   74447}||00011
|-
|$$||[[:d:  Q440531]]||{   54078}||00011
|-
|$$||[[:d:Q20979382]]||{  118932}||00001
|-
|$$||[[:d:  Q921488]]||{   65228}||00001
|-
|$$||[[:d: Q1355458]]||{   50005}||00001
|-
|$$||[[:d:  Q552349]]||{  115095}||00001
|-
|$$||[[:d:  Q207084]]||{   89115}||00111
|-
|$$||[[:d:  Q714047]]||{   54514}||00001
|-
|$$||[[:d:   Q77164]]||{   50530}||00111
|-
|$$||[[:d:   Q60717]]||{   54421}||00111
|-
|$$||[[:d:   Q77159]]||{   63373}||00111
|-
|$$||[[:d:   Q91615]]||{  169469}||00011
|-
|$$||[[:d:   Q77149]]||{  155207}||00011
|-
|$$||[[:d:Q17364412]]||{  176494}||00011
|-
|$$||[[:d:Q29559367]]||{   72191}||00110
|-
|$$||[[:d: Q1681537]]||{  106235}||00011
|-
|$$i||[[:d:Q13990552]]||{   56820}||00001
|-
|$$||[[:d:   Q13538]]||{   92825}||00001
|-
|$$||[[:d:Q24228674]]||{   55122}||00010
|-
|$$||[[:d:  Q176577]]||{  163024}||00101
|-
|$$||[[:d: Q2093033]]||{  104305}||00001
|-
|$$||[[:d:Q49562573]]||{   68248}||00010
|-
|$$||[[:d:  Q373522]]||{  169402}||00011
|-
|$$||[[:d:Q13403768]]||{   53136}||00001
|-
|$$||[[:d:  Q274441]]||{  125578}||00101
|-
|$$||[[:d:  Q212833]]||{   74242}||00001
|-
|$$||[[:d:  Q192661]]||{   68649}||00011
|-
|$$||[[:d:Q16297666]]||{  120830}||00001
|-
|$$||[[:d:  Q649333]]||{  170689}||00011
|-
|$$||[[:d:  Q511986]]||{   77720}||00011
|-
|$$||[[:d:Q15759429]]||{   74862}||00011
|-
|$$||[[:d: Q5284058]]||{   69781}||00011
|-
|$$||[[:d:Q29918446]]||{  195161}||00101
|-
|$$||[[:d:  Q315970]]||{   53215}||00001
|-
|$$||[[:d:Q13360044]]||{   51840}||00001
|-
|$$||[[:d:  Q251980]]||{   82360}||00011
|-
|$$!||[[:d:  Q708313]]||{   93908}||00001
|-
|$$||[[:d:  Q319572]]||{   99916}||00011
|-
|$$||[[:d:Q24061220]]||{   70605}||00010
|-
|$$||[[:d:Q15714673]]||{  179609}||00011
|-
|$$||[[:d:  Q708345]]||{   91065}||00001
|-
|$$||[[:d:Q30528312]]||{  106503}||00001
|-
|$$||[[:d:  Q311222]]||{  210592}||00011
|-
|$$||[[:d:Q16735453]]||{  225856}||00001
|-
|$$||[[:d:  Q245241]]||{   69590}||00001
|-
|$$||[[:d:Q14905846]]||{  182367}||00001
|-
|$$||[[:d:  Q324515]]||{   63576}||00001
|-
|$$||[[:d:  Q295483]]||{   91205}||00001
|-
|$$||[[:d: Q7035585]]||{  228645}||00001
|-
|$$||[[:d: Q1588571]]||{  163687}||00011
|-
|$$||[[:d: Q3502012]]||{   78201}||00001
|-
|$$||[[:d:  Q295866]]||{  135720}||00011
|-
|$$||[[:d:  Q441037]]||{   53025}||00001
|-
|$$||[[:d:  Q527839]]||{   70119}||00101
|-
|$$||[[:d: Q6835083]]||{  179303}||00011
|-
|$$||[[:d:Q18810082]]||{  106406}||00011
|-
|$$||[[:d:  Q211636]]||{  103690}||00001
|-
|$$||[[:d:  Q317961]]||{  116204}||00011
|-
|$$||[[:d:  Q441027]]||{   93107}||00001
|-
|$$||[[:d:  Q409547]]||{   63503}||00001
|-
|$$||[[:d:Q18927958]]||{  182000}||00001
|-
|$$||[[:d:  Q345626]]||{  226480}||00011
|-
|$$||[[:d: Q1338865]]||{   66955}||00001
|-
|$$||[[:d:  Q523725]]||{   58521}||00001
|-
|$$||[[:d:  Q457011]]||{  118550}||00001

|}


Man..:920
Women: 1159

Page [[nl:Gebruiker:Edoderoo/Tennis-stats]] saved
import pywikibot

repo=pywikibot.Site('wikidata','wikidata').data_repository()
wd=pywikibot.ItemPage(repo,'Q23448791')
wd.get(get_redirect=True)
def getUICcode_fromPerson(wd):
  if ('P27' in wd.claims):
    con=wd.claims['P27'][0].getTarget()
    con.get(get_redirect=True)
    if ('P2981' in con.claims):
      uic=con.claims['P2981'][0].getTarget()
      return(uic)
  return('')
BY