In [ ]:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# (C) Edoderoo/Edoderoobot (meta.wikimedia.org), 2016–2019
# Distributed under the terms of the CC-BY-SA 3.0 licence.

#Q13005188 mandal 

import pywikibot
from pywikibot import pagegenerators as pg
from pywikibot.data import api
import codecs
import sys
import datetime
from datetime import datetime, date, time, timedelta

debugedo=True   #use one item, just to test
debugedo=False  #use wd-query, process a lot

#demoniem = P1549
geborenCLAIM =     'P569'
gestorvenCLAIM=    'P570'
is_eenCLAIM=       'P31'
genderCLAIM =      'P21'
countryCLAIM =     'P17'
female_genderPROP ='Q6581072'
male_genderPROP =  'Q6581097'
gelegen_inCLAIM=   'P131'
beroepCLAIM=       'P106'
items2do = 0    #global parameter to print progress 
commit=False    #no changes online, only to the logfiles
commit=True     #write changes to the database
CheckFilled=True
NoCheckFilled=False
SkipFilled=True
ReplaceContents=False
MultiLanguage=True
mailstart=datetime.now()
mailmessage='<default message>'
totaledits=0

lng_canbeused = ['en','de','fr','it','es','pt','ca','dk','cs','hr','nl','ro','sh','vi','eo','simple','eu','zea','li','fy','oc','af','nb','no','pl','si','sv','wa',]
default_query = 'claim[31:5] and claim[106] and claim[27] and link[nlwiki]'  # people with an occupation, a country and a page on nl-wiki
default_query = 'link[nlwiki]'   # just go along all nl-wiki articles, and see by P31 what you can do
update_label_allowed=[
  'Q5',      #human
  'Q318',    #galaxy
  'Q523',    #ster
  'Q532 ',   #dorp/village
  'Q3863',   #planetoide
  'Q6243',   #veranderlijke ster
  'Q7187',   #gen
  'Q7366',   #lied
  'Q7889',   #computerspel
  'Q8054',   #proteine
  'Q8502',   #berg
  'Q9842',   #basisschool
  'Q13632',  #planetaire nevel
  'Q16521',  #taxon
  'Q30198',  #moeras
  'Q30612',  #klinisch onderzoek
#  'Q39614', #begraafplaats
  'Q54050',  #heuvel
  'Q79007',  #straat
  'Q95074',  #personage
  'Q101352', #last name
  'Q115518', #planetaire nevel
  'Q130019', #koolstofster
  'Q134556', #music single
  'Q178122', #aria
  'Q191067', #redactieel artikel
  'Q202444', #first name
  'Q204194'  #absorptienevel
  'Q207628', #compositie
  'Q215380', #musicband
  'Q222910', #music album
  'Q253019', #ortsteil
  'Q277338', #pseudogen
  'Q620615', #mobile app
  'Q737498', #wetenschappelijk tijdschrift 
  'Q486972', #nederzetting
  'Q482994', #music album
  'Q726242', #RRLYR-ster
  'Q732577', #publicatie
  'Q1149652', #district in India
  'Q1153690', #lange periode variabele ster    
  'Q1332364', #roterende ellipsoide ster
  'Q1348589', #maankrater
  'Q1457376', #overlappende dubbelster
  'Q1690211', #openbare wasplaats
  'Q2065704', #tingrett
  'Q2247863', #hardlopende ster
  'Q4502142', #visueel kunstwerk
  'Q5633421', #scientific magazine
  'Q7302866', #nummer van een CD
  'Q13005188', #mandal in India
  'Q13442814', #scientific article
  'Q15917122', #rotating variable ster
  'Q19389637', #biografisch artikel
  'Q20741022', #model digital camera
  'Q21014462', #cel lijn
  'Q21278897', #wiktionary redirect
  'Q21573182', #natuurmoment in Duitsland
  'Q23925393', #douar, Marokkaans bestuurlijkg gebied
  'Q26703203', #stolperstein
  'Q50386450', #opera-personage
  'Q53764738', #chinees karakter
  'Q56436498', #dorp in India
  'Q66619666', #rode reuzentak-ster
  'Q67206691', #infraroodbron
  'Q71963409', #comact group of galaxy
  'Q72802508', #emissielijn-sterrenstelsel
  'Q72803622', #emissie-lijn-ster
  'Q88965416', #Zweedse schooleenheid
                      ]
run_lng = 'nl'
txt2skip = '|skip!|'
output2screen = False
prelog = True
prelog = False   #if set to True, it will write an extra logfile containing the item before it is processed, helpful in case of an error on unknown items
skiplog= True

all_types_list=[
                'Q571',    #boek
                'Q134556', #single
                'Q16970',  #kerkgebouw
                'Q34763',  #schiereiland
                'Q95074',  #personage
                'Q2912397' #eendaagse wielerwedstrijd
                'Q23442',  #eiland
                'Q23397',  #meer
                'Q102496', #parochie
                'Q273057', #discografie
                'Q207628', #compositie
                
                
               ]

simple_set_byP131=[
            'Q24764','Q70208','Q127448','Q203300','Q262166','Q262166','Q378508','Q484170','Q493522','Q612229','Q640364','Q659103','Q667509','Q747074','Q755707','Q856076','Q856079','Q955655','Q1054813',
            'Q13218690', 'Q15127838', 'Q2261863', 'Q494721',#steden
            'Q1363145','Q1500350','Q1500352','Q1530824','Q1840161','Q2661988','Q2590631','Q2460358','Q1849719','Q2989398','Q3327873','Q3685462','Q5154047','Q6784672','Q16739079','Q20538317',
            'Q23925393', #marokkaanse douar 
            'Q23012917', 'Q2225692','Q4174776','Q13100073','Q23827464','Q3558970','Q15630849','Q21672098', #dorpen
            'Q188509', #buitenwijk
            'Q9842',  #basisschool
            'Q3914', #school
            'Q355304', #watergang
            'Q54050',#heuvel
            'Q166735',#broekbos
            '','','','','','','','','','','','','','',
           ]              
               

def sendmail(changemail,totalreads,totaledits):
  global mailmessage
  global mailstart
  mailend=datetime.now().strftime("%Y-%b-%d    ––>[%H:%M]<––" )
    
  if mailmessage=='hourly':
    subj='hourly--Set-nl-Description--hourly'
  else:
    subj='Set-nl-Description'    
        
  mailtxt=f'Start: {mailstart}\nType:{mailmessage}\nEnd: {mailend}\n\n{changemail}\nEdits(y): {totaledits}\nItems: {totalreads}'
  mailuser=pywikibot.User(pywikibot.Site('nl'),'Edoderoo')
  mailuser.send_email(subject=subj, text=mailtxt)

def log_premature(itemno):
  with codecs.open("NL-omschrijving.prelog.csv","a", encoding="utf-8") as logfile:
    logfile.write('%s\n' % (itemno))
  logfile.close

def log_skipped(itemno):
  with codecs.open("NL-omschrijving.skiplog.csv","a", encoding="utf-8") as logfile:
    logfile.write('%s\n' % (itemno))
  logfile.close
  
  
def logme(verbose, formatstring, *parameters):
  with codecs.open("NL-omschrijving.log.csv", "a", encoding="utf-8") as logfile:
    formattedstring = u'%s%s' % (formatstring, '\n')

    outputstr = (formatstring % (parameters))
    if ((outputstr[:7]=='Unknown') and (outputstr.find('|')==0)):   #Unknown error, no extra parameter, do not log
      pass
    else:  
       try:   
         logfile.write(formattedstring % (parameters) )
       except :
         exctype, value = sys.exc_info()[:2]
         print("1) Error writing to logfile on: [%s] [%s]" % (exctype, value))
         verbose = True    #now I want to see what!   
       logfile.close()
  if verbose:
    print(formatstring % (parameters))  

def log_unknown(verbose, formatstring, *parameters):    
  if False:
    with codecs.open("NL-omschrijving.missing.csv", "a", encoding="utf-8") as logfile:
     formattedstring = u'%s%s' % (formatstring, '\n')
    
     try:   
       logfile.write(formattedstring % (parameters))
     except :
       print("2) Error writing to logfile on")   
       verbose = True    #now I want to see what!
    logfile.close()
    if verbose:
     print(formatstring % (parameters))  

def get_property_id(findProperty):
 switcher={ 'date of birth' : 'P569',
            'is a' : is_eenCLAIM,
            'occupation' : beroepCLAIM,
            'country of citizenship' : 'P27'
          }
 return switcher.get(findProperty,'zxx')

def nameofcitizenship(CountryName,Occupation) :
           switcher = {
             'Koninkrijk der Nederlanden'     : 'Nederlands',
             'Nederland'                      : 'Nederlands',
             'Frankrijk'                      : 'Frans', 
             'Verenigde Staten van Amerika'   : 'Amerikaans', 
             'Spanje'                         : 'Spaans' ,
             'Verenigd Koninkrijk'            : 'Brits',
             'Duitsland'                      : 'Duits',
             'Rusland'                        : 'Russisch' ,
             'Polen'                          : 'Pools',
             'Luxemburg'                      : 'Luxemburgs',
             'Duitse Democratische Republiek' : 'Oost-Duits',
             'India'                          : 'Indiaas',
             'Turkije'                        : 'Turks',
             'Finland'                        : 'Fins',
             'Volksrepubliek China'           : 'Chinees',
             'Japan'       : 'Japans',
             'Zweden'      : 'Zweeds',
             'Canada'      : 'Canadees',
             'Colombia'    : 'Colombiaans',
             'Hongarije'   : 'Hongaars',
             'Argentinië'  : 'Argentijns',
             'Noorwegen'   : 'Noors',
             'Sovjet-Unie' : 'Russisch',
             'Spanje'      : 'Spaans',
             'Portugal'    : 'Portugees',
             u'Denemarken' : 'Deens',
             '' : '',
             u'Italië' : 'Italiaans' ,
             u'België' : 'Belgisch' ,
           }
           demonym = switcher.get(CountryName,"")
           if demonym=="": 
             return Occupation+' uit '+CountryName
           else:
             return demonym.strip()+' '+Occupation

def get_lng_description(language, wikidataitem):
  if language in wikidataitem.descriptions:
    return wikidataitem.descriptions[language]
  else:
    return('')  

def make_yeardatestr(thisdate):    
    #import pdb; pdb.set_trace();
    if not(thisdate is None): 
      if thisdate.precision<9 : return('') #not a full year specified  9=only year, 11=dd-mm-yy
      if thisdate.year<0:
          return(str(abs(thisdate.year))+'v Chr')
      else :
          return(str(thisdate.year))
    else :
      return ('')


def get_female_label_form(wditem,lng,male_form):
  female = male_form
  if ('P2521' in wditem.claims):
    for tryclaim in wditem.claims['P2521']:
      if tryclaim.target.language==lng:
        female = tryclaim.target.text
  return (female)
  
def is_female(wditem):
  if genderCLAIM in wditem.claims:
    LNKgender = wditem.claims.get(genderCLAIM)[0].getTarget()
    return (LNKgender.title()==female_genderPROP)
  return(False)
  
def its_a_firstname(lng,repo,wd):
  
  if (is_eenCLAIM in wd.claims):
    for p31 in wd.claims[is_eenCLAIM]:
      title=p31.getTarget().title()
      if (title=='Q3409032'): return('zowel mannelijke als vrouwelijke voornaam','') #both male/female first name
      if (title=='Q11879590'): return('vrouwelijke voornaam','')
      if (title=='Q12308941'): return('mannelijke voornaam','')       

  if ('en' in wd.descriptions):
   if (wd.descriptions['en']==u'female given name'): return('vrouwelijke voornaam','')
   if (wd.descriptions['en']==u'male given name'): return('mannelijke voornaam','')
   
  if ('de' in wd.descriptions):
   if (wd.descriptions['de']==u'weiblicher Vorname'): return('vrouwelijke voornaam','')
   if (wd.descriptions['de']==u'männlicher Vorname'): return('mannelijke voornaam','')
   
  if ('fr' in wd.descriptions): 
   if (wd.descriptions['fr'] ==u'prénom féminin'): return('vrouwelijke voornaam','')
   if (wd.descriptions['fr'] ==u'prénom masculin'): return('mannelijke voornaam','')
   if (wd.descriptions['fr'] ==u'prénom épicène'): return('zowel mannelijke als vrouwelijke voornaam','')

  if ('pl' in wd.descriptions): 
   if (wd.descriptions['pl'] ==u'imię żeńskie'): return('vrouwelijke voornaam','')
   if (wd.descriptions['pl'] ==u'imię męskie'): return('mannelijke voornaam','')
   if (wd.descriptions['pl'] ==u'xxx'): return('zowel mannelijke als vrouwelijke voornaam','')
   
  if ('it' in wd.descriptions): 
   if (wd.descriptions['it'] ==u'prenome femminile'): return('vrouwelijke voornaam','')
   if (wd.descriptions['it'] ==u'prenome maschile'): return('mannelijke voornaam','')
   if (wd.descriptions['it'] ==u'xxx'): return('zowel mannelijke als vrouwelijke voornaam','')

  if ('hy' in wd.descriptions): 
   if (wd.descriptions['hy'] ==u'իգական անձնանուն'): return('vrouwelijke voornaam','')
   if (wd.descriptions['hy'] ==u'արական անձնանուն'): return('mannelijke voornaam','')
   if (wd.descriptions['hy'] ==u'xxx'): return('zowel mannelijke als vrouwelijke voornaam','')

  if ('nb' in wd.descriptions): 
   if (wd.descriptions['nb'] ==u'kvinnenavn'): return('vrouwelijke voornaam','')
   if (wd.descriptions['nb'] ==u'mannlig fornavn'): return('mannelijke voornaam','')
   if (wd.descriptions['nb'] ==u'xxx'): return('zowel mannelijke als vrouwelijke voornaam','')
  
  return ('voornaam','')
  
"""
For a person, we take the occupation and country of citizenship, e.g. "association football player from Germany", 'presentator from Italy', "accountant from the United States", 'politician from Ukraine', etc
"""             
  
def its_a_person(lng, repo, WDIperson):
    missing = u'' 
    update_desc = False
    if lng in WDIperson.descriptions:
       update_desc = (WDIperson.descriptions[lng].lower() in ['','person','persoon','sporter','politicus','politica','mens']) or \
                     (WDIperson.descriptions[lng].lower().find('n/a') > 0) or \
                     (WDIperson.descriptions[lng].lower().find('sporter') > 0) or \
                     (WDIperson.descriptions[lng].lower().find('dramaturgino') > 0) or \
                     (WDIperson.descriptions[lng].lower().find('scenografino') > 0) or \
                     (WDIperson.descriptions[lng].find('(-)')>0) 

    LNKinstance_of = WDIperson.claims.get(is_eenCLAIM)[0].getTarget()
    if not(LNKinstance_of is None): 
      WDIinstance =  pywikibot.ItemPage(repo,LNKinstance_of.title())
      WDIinstance.get(get_redirect=True)
      if lng in WDIinstance.labels:
        prnInstance = WDIinstance.labels[lng]
      else : 
        prnInstance = u''
        missing = WDIperson.title()
    else :
      prnInstance = u'1 n/a: '+WDIperson.title()+' '
      return('',txt2skip)

    prnOccupation = u'2 n/a '
    if beroepCLAIM in WDIperson.claims:   #beroep
        LNKoccupation = WDIperson.claims.get(beroepCLAIM)[0].getTarget()
        try :
          WDIoccupation = pywikibot.ItemPage(repo,LNKoccupation.title())
          WDIoccupation.get(get_redirect=True)
          if (lng in WDIoccupation.labels) : 
            if (is_female(WDIperson)):
              prnOccupation = get_female_label_form(WDIoccupation,lng,WDIoccupation.labels[lng])
            else:
              prnOccupation = WDIoccupation.labels[lng]
          else : 
            prnOccupation = u'3 n/a'
            missing = txt2skip
        except :
          missing = WDIperson.title()
          prnOccupation = u'4 n/a'
          print("Except :-(")
    else :
      return(u'',txt2skip)

    if 'P27' in WDIperson.claims:  #country of origin
        prnCountry = u'n/a = '
        LNKcountry = WDIperson.claims.get('P27')[0].getTarget()
        try :
          WDIcountry = pywikibot.ItemPage(repo,LNKcountry.title())
          WDIcountry.get(get_redirect=True)
          if (lng in WDIcountry.labels): 
            prnCountry = WDIcountry.labels[lng]
          else : 
            missing = WDIcountry.title()
        except :
          missing = WDIperson.title()
    else :
      return('',txt2skip) 

    geboortejaarstr = '?'
    if (geborenCLAIM in WDIperson.claims):
      geboortejaarstr=make_yeardatestr(WDIperson.claims.get(geborenCLAIM)[0].getTarget())    
    
    if (gestorvenCLAIM in WDIperson.claims):
      sterfdatum = WDIperson.claims.get(gestorvenCLAIM)[0].getTarget()
      if not(sterfdatum is None): 
        levenjaarstr = ' ('+geboortejaarstr+'-'+make_yeardatestr(sterfdatum)+')'
      else:
        levenjaarstr = ' ('+geboortejaarstr+'-?)'
    else:
      geboortejaarstr=''
      levenjaarstr=''

    my_description = nameofcitizenship(prnCountry,prnOccupation)+levenjaarstr
    if (my_description==''):
      if 'P496' in wd.claims: #ORCID-id
        my_description='wetenschapper'
        missing=''
    return(my_description, missing)

def its_a_generalthing(lng,repo,wditem,shortstr,longdescrstr,myclaim,MultiLng,force):
  if (lng in wditem.descriptions) and (not force):
    if (wditem.descriptions[lng]!=shortstr):
      return('',txt2skip)
  claimstr=u''
  try:
    if (myclaim in wditem.claims):
      LNKitem=wditem.claims.get(myclaim)[0].getTarget()
      if not (LNKitem is None):
        WDIitem = pywikibot.ItemPage(repo,LNKitem.title())
        WDIitem.get(get_redirect=True)
        if lng in WDIitem.labels:
          claimstr=WDIitem.labels[lng]
        elif MultiLng:
          for trylng in lng_canbeused:
            if (claimstr=='') and (trylng in WDIitem.labels):
               claimstr = WDIitem.labels[trylng]
  except:
    pass
  if claimstr=='':
    return(shortstr,'')
  else:
    return(('%s %s' % (longdescrstr,claimstr)),'')

def it_was_a_generalthing(lng,repo,wditem,shortstr,longdescrstr,myclaim,oneLng):
  claimstr=u''
  try:
    if oneLng:
      if (myclaim in wditem.claims):
        LNKitem=wditem.claims.get(myclaim)[0].getTarget()
        if not (LNKitem is None):
          WDIitem = pywikibot.ItemPage(repo,LNKitem.title())
          WDIitem.get(get_redirect=True)
          if lng in WDIitem.labels:
            claimstr=WDIitem.labels[lng]
          else:
            for trylng in lng_canbeused:
              if (claimstr=='') and (trylng in WDIitem.labels):
                 claimstr = WDIitem.labels[trylng]
    else:
      claimstr,missing=get_description(lng,wditem)
  except:
    pass
    
  if claimstr=='':
    return(shortstr,'')
  else:
    return(('%s%s' % (longdescrstr,claimstr)),'')

def get_label_txt(lng,repo,wdi,property,array=0,fallback=False):
  try:
   if property in wdi.claims:
    if (len(wdi.claims[property])>array):
      lnkProperty=wdi.claims.get(property)[array].getTarget()
      propwdi=pywikibot.ItemPage(repo,lnkProperty.title())
      propwdi.get(get_redirect=True)
      if (propwdi.exists()):
       if (lng in propwdi.labels):
        return(propwdi.labels[lng])
       elif (fallback):
         for fallbacklng in lng_canbeused:
           if fallbacklng in propwdi.labels:
             return(propwdi.labels[fallbacklng])
  except:
    print('get_label failed')
  return('')

def its_a_headquarted_thing(lng,repo,wdi,thing):
  where=get_label_txt(lng,repo,wdi,'P159',fallback=True)
  if (where!=''):
    return(f'{thing} {where}','')
  else:
    return('',wdi.title())

def its_something_in_an_entity(lng,repo,wdi,something):
  prnEntity = ''
  prnCountry = ''

  if (gelegen_inCLAIM in wdi.claims):
    try:
      LNKentity = wdi.claims.get(gelegen_inCLAIM)[0].getTarget()
      WDIentity = pywikibot.ItemPage(repo,LNKentity.title())
      WDIentity.get(get_redirect=True)
      if (lng in WDIentity.labels):
        prnEntity = WDIentity.labels[lng]
      else:
        return('',txt2skip)
    except :
      missing = wdi.title()

  if countryCLAIM in wdi.claims:  
    try :
      LNKcountry = wdi.claims.get(countryCLAIM)[0].getTarget()
      if (LNKcountry!=None):
       WDIcountry = pywikibot.ItemPage(repo,LNKcountry.title())
       WDIcountry.get(get_redirect=True)
       if (lng in WDIcountry.labels): 
        prnCountry = WDIcountry.labels[lng]
       else : 
        prnCountry = u''
        missing = WDIcountry.title()
    except :
      missing = wdi.title()
    
    if (prnCountry!='') and (prnEntity!=''):
      return('%s %s, %s' % (something, prnEntity, prnCountry),'')  
    elif (prnCountry!=''):
      return('%s %s' % (something, prnCountry),'')
    elif (prnEntity!=''):
      return('%s %s' % (something, prnEntity),'')
    else:
      return('',txt2skip)  
  else:
    return('',txt2skip)  
    
def its_something_in_a_country(lng,repo,wdi,something,skipiffilled):
    prnCountry = u'unknown'
    if (skipiffilled):
     if (lng in wdi.descriptions):
      if (wdi.descriptions[lng] != ''):
        return(wdi.descriptions[lng],txt2skip)
    missing = u''
    if countryCLAIM in wdi.claims:  
      LNKcountry = wdi.claims.get(countryCLAIM)[0].getTarget()
      try :
        WDIcountry = pywikibot.ItemPage(repo,LNKcountry.title())
        WDIcountry.get(get_redirect=True)
        if (lng in WDIcountry.labels): 
          prnCountry = WDIcountry.labels[lng]
        else : 
          prnCountry = u'n/a = '
          missing = WDIcountry.title()
      except :
        missing = wdi.title()
    elif 'P495' in wdi.claims :
      LNKcountry = wdi.claims.get('P495')[0].getTarget()
      try :
        WDIcountry = pywikibot.ItemPage(repo,LNKcountry.title())
        WDIcountry.get(get_redirect=True)
        if (lng in WDIcountry.labels): 
          prnCountry = WDIcountry.labels[lng]
        else : 
          prnCountry = u'n/a = '
          missing = WDIcountry.title()
      except :
        missing = wdi.title()
    else:
      return('' ,txt2skip) 
    return(something.strip()+ ' '+prnCountry,missing)      
        
def its_canton_of_France(lng,repo,wdi):
  current_desc = ''
  missing = ''
  my_description = 'kanton in Frankrijk'
  if (lng in wdi.descriptions):
    current_desc = wdi.descriptions[lng]
  if (current_desc==''): 
    if gelegen_inCLAIM in wdi.claims:
      LNKcommunity = wdi.claims.get(gelegen_inCLAIM)[0].getTarget()
      WDIcommunity = pywikibot.ItemPage(repo,LNKcommunity.title())
      WDIcommunity.get(get_redirect=True)
      if lng in WDIcommunity.labels:
        my_description = 'kanton in '+WDIcommunity.labels[lng]+', Frankrijk'
  else:
    missing = txt2skip  
  return(my_description,missing)
        
def its_a_mountain(lng,repo,wdi):
    return(its_something_in_a_country(lng,repo,wdi,'berg in',True))      
      
def its_disambigue(lng,repo,wdi):
  if (lng in wdi.descriptions) or (len(wdi.claims)>1):   #there is already a description, skip this one
    return('',txt2skip)
  return('Wikimedia-doorverwijspagina','')      #use default description

def its_a_thing_located_in_country(lng,repo,wditem,countryname, thing):
    if (lng in wditem.descriptions):
      return(wditem.descriptions[lng],txt2skip)
    if (gelegen_inCLAIM in wditem.claims):
      LNKcommunity = wditem.claims.get(gelegen_inCLAIM)[0].getTarget()
      WDIcommunity = pywikibot.ItemPage(repo,LNKcommunity.title())
      WDIcommunity.get(get_redirect=True)
      
      if (lng in WDIcommunity.labels):
        return(thing+u' in '+WDIcommunity.labels[lng]+u', '+countryname, '')     
      else:
        return(thing+u' in '+countryname, WDIcommunity.title())
    else:
      return(thing+u' in '+countryname,wditem.title())

def its_a_publication(lng,repo,wditem):
  over=uitgever=missing=datumstr=''
  if ('P921' in wditem.claims):
    over,missing=its_a_generalthing(lng,repo,wditem,'', 'over', 'P921',True,False)
  if ('P123' in wditem.claims):
    uitgever,missing=its_a_generalthing(lng,repo,wditem,'','van uitgever','P123',True,False)
  if ('P577' in wditem.claims):
    datumstr,missing='',''
  return('publicatie',missing)  

def its_an_episode(lng, repo, wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)
  if 'P179' in wditem.claims: #serie
    LNKseries = wditem.claims.get('P179')[0].getTarget()
    WDIseries = pywikibot.ItemPage(repo,LNKseries.title())
    WDIseries.get(get_redirect=True)
    
    serienaam,missing=get_description(lng,WDIseries)
    if (serienaam=='') or (missing==txt2skip):
      return('aflevering van '+WDIseries.title(), txt2skip)
    else :
      return('aflevering van ' + serienaam,'')
      
  else:
    return('',txt2skip)
    
def its_a_list(lng,repo,wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)  
  return('Wikimedia-lijst','')
    
def its_a_town(lng,repo,wditem):
  return its_something_in_a_country(lng,repo,wditem,'stad in',True)  
  
def its_a_football_team(lng, repo, wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)  
  return(its_something_in_a_country(lng,repo,wditem,'voetbalteam uit',True))  

def its_a_band(lng,repo,wditem):
    if (lng in wditem.descriptions):
         return(wditem.descriptions[lng],txt2skip)
    missing = u''
    return its_something_in_a_country(lng,repo,wditem,'muziekgroep uit',True)
    
  
def its_a_tvseries(lng,repo,wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)
  return(its_something_in_a_country(lng,repo,wditem,'televisieserie uit',True))

def its_a_tvprogram(lng,repo,wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)
  if (countryCLAIM in wditem.claims):
    return(its_something_in_a_country(lng,repo,wditem,'televisieprogramma uit',True))
  else:
    return('televisieprogramma','')

def its_a_musicalbum(lng,repo,wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)
  if 'P175' in wditem.claims:
    LNKartist = wditem.claims.get('P175')[0].getTarget()
    WDIartist=pywikibot.ItemPage(repo,LNKartist.title())
    WDIartist.get(get_redirect=True)
    if (lng in WDIartist.labels):
      return('muziekalbum van '+WDIartist.labels[lng],'')
  
  return('muziekalbum','')
  
  
def its_a_book(lng,repo,wditem):
  if (lng in wditem.descriptions):
    if (wditem.descriptions[lng] != u'boek'):
      return('',txt2skip)
  return its_a_generalthing(lng,repo,wditem,'boek','boek van','P50',True,False)


def its_a_nummer(lng,repo,wditem):
  if (lng in wditem.descriptions):
    if not(wditem.descriptions[lng] in [u'nummer','single','lied','']):
      return('',txt2skip)
  return its_a_generalthing(lng,repo,wditem,'nummer','nummer van','P175',True,False)


def its_a_single(lng,repo,wditem):
  if (lng in wditem.descriptions):
    if not(wditem.descriptions[lng] in [u'single','nummer','lied','']):
      return('',txt2skip)
  return its_a_generalthing(lng,repo,wditem,'single','single van','P175',True,False)

def its_a_carmodel(lng,repo,wditem):  #automodel van P176
  manufacturer = u''
  if (lng in wditem.descriptions):
    if(wditem.descriptions[lng] not in [u'automodel','']):
      return('',txt2skip)
  return its_a_generalthing(lng,repo,wditem,'automodel','automodel van','P176',True,False)

def its_a_discography(lng,repo,wditem):
  if 'P175' in wditem.claims:
    artistLNK = wditem.claims.get('P175')[0].getTarget()
    if not(artistLNK is None):
      wdArtist=pywikibot.ItemPage(repo,artistLNK.title())
      wdArtist.get(get_redirect=True)
      if lng in wdArtist.labels:
        return ('discografie van '+wdArtist.labels[lng],'')
      else:
        for trylng in lng_canbeused:
          if trylng in wdArtist.labels:
            return('discografie van '+wdArtist.labels[trylng],'')
  return('discografie','')

def its_chemical(lng,repo,wditem):
  return('',txt2skip)  
  
def action_one_P131_item(lng,repo,oneitem):  
   global totaledits
   
   if (lng in oneitem.descriptions):
     nld=oneitem.descriptions[lng]
   else :
     nld=''
   if (lng in oneitem.labels):
     nll = oneitem.labels[lng]      
   else:
     nll = ''
     
   adminname=''
   isaname=''
   countryname=''
   
   if ('P31' in oneitem.claims):
     LNKisa=oneitem.claims.get('P31')[0].getTarget()
     if not LNKisa is None:
       isa=pywikibot.ItemPage(repo,LNKisa.title())
       isa.get(get_redirect=True)
       if lng in isa.labels:
         isaname = isa.labels[lng]
   if (isaname in ['dorp in China']):
      shortname='dorp'
   else:
      shortname=isaname      
        
   if (gelegen_inCLAIM in oneitem.claims):
     LNKadmin=oneitem.claims.get(gelegen_inCLAIM)[0].getTarget()
     if not LNKadmin is None:
       admin=pywikibot.ItemPage(repo,LNKadmin.title())
       admin.get(get_redirect=True)
       if lng in admin.labels:
         adminname = admin.labels[lng]
   if (countryCLAIM in oneitem.claims):
     LNKcountry=oneitem.claims.get(countryCLAIM)[0].getTarget()
     if not LNKcountry is None:
       country=pywikibot.ItemPage(repo,LNKcountry.title())
       country.get(get_redirect=True)
       if lng in country.labels:
         countryname = country.labels[lng]
   data={}
   found=False
   if (not lng in oneitem.labels): 
     for plang in lng_canbeused:
       if (plang in oneitem.labels) and not found:
         data.update({'labels': { lng:oneitem.labels[plang]  }})
         found=True
   
   if (adminname==''):
     newdescription = '%s' % isaname
   else:
     newdescription='%s in %s, %s' % (shortname,adminname,countryname)
   if (isaname!='') and (nld in['','dorp','dorp in China','gemeente','gemeente in China']):
     data.update({'descriptions': { lng: newdescription }})
   try:  
     oneitem.editEntity(data,summary=u'nl-description, [[User:Edoderoobot/Set-nl-description|python code]], logfile on https://goo .gl/BezTim')
     logme(False, '%s|%s|%s|%s|%s|%s|%s',datetime.now().strftime("%Y-%b-%d/%H:%M:%S"),oneitem.title(),lng,newlabel,orig_desc,my_description,placefound)
     totaledits += 1
     return(1)
   except ValueError:
     log_unknown(False, "ValueError occured on %s",oneitem.title())
   except :
     log_unknown(False, "Undefined error occured on %s-[%s]",oneitem.title(),'simpleP131')
     pass
   else :
     pass #print("Else:")
   return(0)

def its_a_sports_season(lng,repo,wditem):
  if ('P641' in wditem.claims):
    LNKsport=wditem.claims.get('P641')[0].getTarget()
    if (not(LNKsport is None)):
      sport=pywikibot.ItemPage(repo,LNKsport.title())
      sport.get(get_redirect=True)
      if (lng in sport.labels):
        return(('sportseizoen van een %scompetitie'%sport.labels[lng]),'')
      else:
        return('sportseizoen van een competitie','')
  return ('sportseizoen van een competitie','')

def its_an_audio_drama(lng,repo,wditem):
  if ('P179' in wditem.claims):
    return its_a_generalthing(lng,repo,wditem,'hoorspel','hoorspel van','P50',True,False)
  if ('P50' in wditem.claims):
    return its_a_generalthing(lng,repo,wditem,'hoorspel','hoorspel van','P50',True,False)
  if ('P495' in wditem.claims):
    return its_a_generalthing(lng,repo,wditem,'hoorspel','hoorspel uit','P495',True,False)
  return('hoorspel','')

def its_a_film(lng,repo,wditem):
  if 'P57' in wditem.claims:
    LNKdirector=wditem.claims.get('P57')[0].getTarget()
    if not(LNKdirector is None):
      LNKdirector=pywikibot.ItemPage(repo,LNKdirector.title())
      LNKdirector.get(get_redirect=True)
      directorname,missing=get_description(lng,LNKdirector)
      if (directorname!=''):
        return('film van %s' % directorname,'')
  return('film','')
  
def its_a_taxon(lng,repo,wditem):
  """
  read P171/mother taxon until taxo-rang/P105 is <Q19970288/no value> -> that mother taxon is the first part (insect/)
  """    
  if (lng in wditem.descriptions):
    return(wditem.descriptions[lng],'')
  return(u'taxon',u'')
  
def its_a_composition(lng, repo, wditem):
  """
  find composer P86
  """  
  if ('P86' in wditem.claims):
    composerLNK = wditem.claims.get('P86')[0].getTarget()
    if not composerLNK is None:
      composer = pywikibot.ItemPage(repo,composerLNK.title())
      composer.get(get_redirect=True)
      if (lng in composer.labels):
        return('compositie van %s' % composer.labels[lng], '')
  return('compositie','')
  
def its_a_tabon_in_thailand(lng,repo,wditem):
  newdescription = ''
  if (gelegen_inCLAIM in wditem.claims):
    LNKtambon=wditem.claims.get(gelegen_inCLAIM)[0].getTarget()
    if not (LNKtambon is None):
      WDitemtambon=pywikibot.ItemPage(repo,LNKtambon.title())
      WDitemtambon.get(get_redirect=True)
      return(get_description(lng,WDitemtambon))
  return(newdescription,'')      

def get_description(lng, wditem):
  if (lng in wditem.labels):
    return (wditem.labels[lng],'')
  if ('en' in wditem.labels):
    return (wditem.labels['en'],'')
  if ('de' in wditem.labels):
    return (wditem.labels['de'],'')
  if ('nl' in wditem.labels):
    return (wditem.labels['nl'],'')
  if ('fr' in wditem.labels):
    return (wditem.labels['fr'],'')
  if ('it' in wditem.labels):
    return (wditem.labels['it'],'')
  if ('es' in wditem.labels):
    return (wditem.labels['es'],'')
  return('',txt2skip)

def its_a_fictional_character(lng,repo,wditem):
  if ('P1441' in wditem.claims):
    my_description,missing=its_a_generalthing(lng,repo,wditem,'personage','personage uit','P1441',True,False)
  elif ('P1080' in wditem.claims):
    my_description,missing=its_a_generalthing(lng,repo,wditem,'personage','personage uit','P1080',True,False)
  else: 
    my_description='personage'
    missing=''
  return (my_description,missing)

def its_a_computergame(lng, repo, wditem):
  if ('P178' in wditem.claims):
    LNKdeveloper=wditem.claims.get('P178')[0].getTarget()
    if not (LNKdeveloper is None):
      WDitemdeveloper=pywikibot.ItemPage(repo,LNKdeveloper.title())
      WDitemdeveloper.get(get_redirect=True)
      developer_name,missing=get_description(lng,WDitemdeveloper)
      if (developer_name!=''):
        return('computerspel van %s'%developer_name,'')
  if ('P179' in wditem.claims):
    serieLNK=wditem.claims.get('P179')[0].getTarget()
    if not(serieLNK is None):
      WDitemserie=pywikibot.ItemPage(repo,serieLNK.title())
      WDitemserie.get(get_redirect=True)
      seriename,missing=get_description(lng,WDitemserie)
      if (seriename!=''):
        return('computerspel uit de serie %s' % seriename,'')
  return('computerspel','')

def action_one_item(lng, repo, wditem):
    global output2screen
    global items2do
    global totaledits
    
    if (debugedo): print('action-one-item1')
    items_written=items_found=0
    missing = u''
    my_description=u''
    orig_desc = get_lng_description(lng,wditem).lower()
    en_description = u''
    en_description = get_lng_description('en',wditem)
    type_of_item=u''
    placefound=''

    
    items2do -= 1
    
    str1 = '{:>10d}'.format(items2do)
    str2 = '{:>10}'.format(wditem.title())
    
    if commit:
      sys.stdout.write("\r%s%s" % (str1, str2))
    gotP31 = False
    if (is_eenCLAIM in wditem.claims):
      gotP31 = True
      type_id = wditem.claims.get(is_eenCLAIM)[0].getTarget()
      if type_id != None:
        type_of_item = type_id.title()  #we only use the first one, and assume the first one is most relevant
    if (type_of_item!='') :  
      #print('Type: [%s]' % (type_of_item))
      if (False):
        pass #just to have the same structure below
      elif (type_of_item == 'Q5') and (orig_desc in ['','mens','politicus','politica','journalist','maakster','nederlands maakster','televisiepresentator','nederlands maker','onderzoeker','xxx']):
        my_description,missing = its_a_person(lng, repo, wditem)
        placefound='person'
      elif type_of_item=='Q4167410': #disambiguation-page
        if (orig_desc in ['','dp','doorverwijzing','doorverwijspagina']):
          my_description,missing = its_disambigue(lng,repo,wditem)
        placefound='disamb'
      elif type_of_item=='Q8502': #a mountain
        my_description,missing = its_a_mountain(lng,repo,wditem)
        placefound='mountain'
      elif type_of_item=='Q16521': #it is a taxon
        if (orig_desc in ['','']): #old one is blank
          my_description,missing=its_a_taxon(lng,repo,wditem) #fix it to "taxon"
        placefound='taxon'
      elif type_of_item=='Q577': #jaar
        my_description='jaar'
        placefound='jaar'
      elif (type_of_item=='Q515') or (type_of_item=='Q5119') or (type_of_item=='Q1549591') or (type_of_item=='Q3957'):  #stad
        my_description,missing = its_a_town(lng,repo,wditem)
        placefound='town'
      elif type_of_item=='Q747074': #Italian communiity
        my_description,missing = its_a_thing_located_in_country(lng,repo,wditem,u'Italië','dorp')
        placefound='IT-gemeente'
      elif type_of_item=='Q484170': #Franse gemeente 
        my_description,missing = its_a_thing_located_in_country(lng,repo,wditem,u'Frankrijk','gemeente')
        placefound='FR-gemeente'
      elif (type_of_item=='Q262166') or (type_of_item=='Q22865' ): #Duitse gemeente
        my_description,missing = its_a_thing_located_in_country(lng,repo,wditem,u'Duitsland','gemeente')
        placefound='DE-gemeente'
      elif type_of_item=='Q13406463': #wikimedia-lijst
        my_description,missing = its_a_list(lng,repo,wditem)
        placefound='lijst'
      elif type_of_item=='Q476028': #voetbalteam
        my_description,missing = its_a_football_team(lng,repo,wditem)
        placefound='voetbalteam'
      elif type_of_item=='Q11173':#chemische verbinding
        if (orig_desc in ['chemische stof','chemische samenstelling','']):
          my_description = 'chemische verbinding'
        placefound = 'chemische samenstelling'
      elif type_of_item=='Q79529':
        if (orig_desc in ['chemische samenstelling','chemische verbinding']):         #was blank, it should be, but better double check
          my_description='chemische stof' #then use default description
        placefound='chemische stof'
      elif type_of_item=='Q5398426': #tv_series
        my_description,missing=its_a_tvseries(lng,repo,wditem)
        placefound='tvserie'
      elif type_of_item=='Q1983062': #aflevering/episode
        my_description,missing=its_an_episode(lng,repo,wditem)
        placefound='episode'
      elif type_of_item=='Q21191270': #aflevering/episode van tv-serie
        my_description,missing=its_an_episode(lng,repo,wditem)
        placefound='tv-episode'
      elif type_of_item=='Q184188': #Frans kanton
        my_description,missing=its_canton_of_France(lng,repo,wditem)
        placefound='Frans kanton'
      elif type_of_item=='Q318': #sterrenstelsel
        #prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'sterrenstelsel','sterrenstelsel in ','P59',False)
        if (orig_desc in ['sterrenstelsel','galaxy','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'galaxy','sterrenstelsel  in','P59',MultiLanguage,False)
        placefound='galaxy2'
      elif type_of_item=='Q13632': #planetaire nevel
        if (orig_desc in ['planetaire nevel','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'planetaire nevel','planetaire nevel in','P59',MultiLanguage,False)
        placefound='planetaire nevel'
      elif type_of_item=='Q2247863': #hardlopende ster 1153690
        if (orig_desc in ['hardlopende ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'hardlopende ster','hardlopende ster in','P59',MultiLanguage,False)
        placefound='planetaire nevel'
      elif type_of_item=='Q1153690': #lange-periode variabele ster
        if (orig_desc in ['lange-periode variabele ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'lange-periode variabele ster','lange-periode variabele ster in','P59',MultiLanguage,False)
        placefound='lpvs'
      elif type_of_item=='Q115518': #planetaire nevel
        if (orig_desc in ['melkwegstelstel met lage helderheid','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'melkwegstelstel met lage helderheid','melkwegstelstel met lage helderheid in','P59',MultiLanguage,False)
        placefound='planetaire nevel'
      elif type_of_item=='Q67206691': #infraroodbron
        if (orig_desc in ['infraroodbron','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'infraroodbron','infraroodbron in','P59',MultiLanguage,False)
        placefound='planetaire nevel'
      elif type_of_item=='Q215380': #muziekband
        if (orig_desc in ['band','']):
          my_description,missing = its_a_band(lng,repo,wditem)
        placefound='band'
      elif type_of_item=='Q39367': #hondenras
        if (orig_desc in ['hond','']):
          my_description=u'hondenras'
        placefound='hondenras'
      elif type_of_item=='Q34770': #taal
        if (orig_desc in ['taal','']):
          my_description='taal'
          placefound='taal'
      elif type_of_item=='Q482994': #muziekalbum
        if (orig_desc in ['','muziekalbum','album','cd']):
          my_description,missing=its_a_musicalbum(lng,repo,wditem)
          placefound='muziekalbum'
      elif type_of_item=='Q11266439':
        if (orig_desc in ['','template','sjabloon']):
          my_description='Wikimedia-sjabloon'
          placefound='template'
      elif type_of_item=='Q310890':  #monotypiscal taxon
        if (orig_desc in ['taxon','']):  
          my_description = 'monotypische taxon'
          placefound='x'
      elif type_of_item=='Q877358': #resolution of the UN
        if (orig_desc in ['resolutie','']):
          my_description='resolutie van de Veiligheidsraad van de Verenigde Naties'
          placefound='VN-resolutie'
      elif type_of_item=='Q486972':
        l1=orig_desc.find('stad in')
        l2=orig_desc.find('plaats in')
        if (orig_desc in ['stad','nederzetting','']) or (l1>=0) or (l2>=0):
          wditem.descriptions['nl']=''
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'nederzetting in',False)
        placefound='nederzetting'
      elif type_of_item=='Q14752149':  #amateur football club
        if (orig_desc in ['','amateurvoetbalclub']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'amateurvoetbalclub uit',False)
          placefound='amateurvoetbalclub'
      elif type_of_item=='Q43229': #organisation
        if (orig_desc in ['organisatie','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'organisatie uit',False)
          placefound='organisatie'
      elif type_of_item=='Q728937': #railway line
        if (orig_desc in ['spoorlijn','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'spoorlijn in',False)
          placefound='railwayline'
      elif type_of_item=='Q7278': #political party
        if (orig_desc in ['politieke partij','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'politieke partij uit',False)
          placefound='political party'
      elif type_of_item=='Q532':  #dorp in P17
        if (orig_desc in ['dorp','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'dorp in ',False)
          if (my_description in ['d','']):
            my_description = 'dorp'
            missing=''
          placefound='dorp'
      elif type_of_item=='Q46970': #luchtvaartmaatschappij uit P17
        if (orig_desc in ['luchtvaartmaatschappij','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'luchtvaartmaatschappij uit',False)
          placefound='airliner'
      elif type_of_item=='Q15416':   #television program
        if (orig_desc in ['televisieprogramma','']):
          my_description,missing = its_a_tvprogram(lng,repo,wditem)
          placefound='televisieprogramma'
      elif ((type_of_item=='Q783794') or (type_of_item=='Q4830453')):
        my_description,missing = its_something_in_a_country(lng,repo,wditem,'bedrijf uit',True)
        placefound='bedrijf'
      elif type_of_item=='Q11424': #film uit P495 (P577)
        if (orig_desc in ['','film']):
          my_description,missing=its_a_film(lng,repo,wditem)
          placefound='film'
      elif type_of_item=='Q18340514': #gebeurtenis in jaar
        my_description = 'gebeurtenis in jaar'
        placefound='gebeurtenis'
      elif type_of_item=='Q1539532':
        my_description = 'sportseizoen'
        placefound='sportseizoen'
      elif type_of_item=='Q3305213': #schilderij van P170
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'schilderij','schilderij van ','P170',False)
        if (orig_desc in ['schilderij','']) or (prev_desc==orig_desc):
          my_description,missing = its_a_generalthing(lng,repo,wditem,'schilderij','schilderij van','P170',MultiLanguage,False)
          placefound='schilderij'

      elif type_of_item=='Q3231690': #automodel van P176
        if (orig_desc in ['automodel','']):
          my_description,missing = its_a_carmodel(lng,repo,wditem)
          placefound='automodel'
      elif type_of_item=='Q3192808': #commune in Madagascar
        if (orig_desc in ['commune','']):
          my_description='commune in Madagascar'
          placefound='madagascar'
      elif type_of_item=='Q1002697': #periodiek in het genre P136
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'periodiek','periodiek in het genre ','P123',False)
        if (orig_desc in ['periodiek','']) or (prev_desc==orig_desc):
          my_description,missing = its_a_generalthing(lng,repo,wditem,'periodiek','periodiek over','P641',not MultiLanguage,False)
          placefound='periodiek-sport'
      elif type_of_item=='Q18536594': #sportevenement op de Olympische Spelen
        if (orig_desc in ['sportevenement','']):
          my_description = 'sportevenement op de Olympische Spelen'
          placefound='OS-event'
      elif type_of_item=='Q7889':  #computerspel  genre=P136   ontwikkelaar=P178  uitgeverij=P123
        if (orig_desc in ['computerspel','']):
          my_description,missing=its_a_computergame(lng,repo,wditem)
          placefound='computerspel'
      elif type_of_item=='Q659103':  #gemeente in P131, Roemenië
        if (orig_desc in ['gemeente in Roemenie','gemeente in Roemenië','gemeente','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'gemeente in')
          placefound='Roemenie'
      elif type_of_item=='Q15081032': #historisch motorfietsmerk
        if (orig_desc in ['motorfietsmerk','']): 
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'motorfietsmerk uit',False)
          placefound='motorfiets'
      elif type_of_item=='Q178561': #veldslag in #P17
        if (orig_desc in ['veldslag','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'veldslag in',False)
          placefound='veldslag'
      elif type_of_item=='Q618779': #onderscheiding
        if (orig_desc in ['onderscheiding','']):
          my_description,missing='onderscheiding',''
          placefound='awardy'
      elif type_of_item=='Q106259': #polder in P131, P17
        if (orig_desc in ['polder','']):
          my_description, missing = its_something_in_an_entity(lng,repo,wditem,'polder in')
          placefound='polder'
      elif type_of_item=='Q18127': #platenlabel uit P17
        if (orig_desc in ['','']):
          pass
          placefound='recordlabel'
      elif type_of_item=='Q3184121': #gemeente in Brazilië
        if (orig_desc in ['gemeente','gemeente in brazilie','gemeente in brazilië','']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,'gemeente in')
          placefound='Brazil'
      elif type_of_item=='Q2635894':  #hoorspel uit de serie P179/uit P495
        if (orig_desc in ['hoorspel','']):
          my_description,missing=its_an_audio_drama(lng,repo,wditem)
          placefound='hoorspel'
      elif type_of_item=='Q523':  #ster uit het sterrenbeeld P59
        if (orig_desc in ['','ster']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'ster','ster in','P59',MultiLanguage,False)
          placefound='ster'
      elif type_of_item=='Q197': #vliegtuig van P176
        if (orig_desc in ['','vliegtuig']):
          my_description,missing='vliegtuig',''
          placefound='plane'
      elif type_of_item=='Q847017': #sportvereniging uit P17
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q2590631': #gemeente in Hongarije
        if (orig_desc in ['','']):
          my_description = u'gemeente in Hongarije'
          placefound='hungary'
      elif type_of_item=='Q3024240': #historisch land in P30
        if (orig_desc in ['','']):
          my_description = u'historisch land'
          placefound='histland'
      elif type_of_item=='Q253019':
        if (orig_desc in ['','ortsteil','plaats in duitsland']):
          my_description, missing =its_a_thing_located_in_country(lng,repo,wditem,'Duitsland', 'ortsteil')
          placefound='ortsteil';
      elif type_of_item=='Q41710': #etniciteit
        if (orig_desc in ['','']):
          my_description = u'etnische groep'
          placefound='etnic'
      elif type_of_item=='Q11446':  #schip
        if (orig_desc in ['','']):
          my_description = u'schip'
          placefound='schip'
      elif type_of_item=='Q180684': #conflict
        if (orig_desc in ['conflict','']):
          its_something_in_a_country(lng,repo,wditem,'conflict in',False)
          placefound='conflict'
      elif type_of_item=='Q5153359': #cz gemeente
        if (orig_desc in ['','']):
          my_description = u'gemeente in Tsjechië'
          placefound='CZ-gemeente'
      elif type_of_item=='Q1131296': #portugese bestuurslaag, fregusia
        if (orig_desc in ['','']):
          my_description = u'freguesia in Portugal'
          placefound='fregusia'
      elif type_of_item=='Q123705':  #wijk in P131, P17
        if (orig_desc in ['','wijk']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'wijk in')
          placefound='wijk'
      elif type_of_item=='Q14659': #heraldisch wapen uit P17
        if (orig_desc in ['heraldisch wapen','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'wapen uit ',True)
          placefound='heraldiek'
      elif type_of_item=='Q2831984': #stripalbum uit de serie P179
        if (orig_desc in ['','stripalbum']):
          my_description,missing = its_a_generalthing(lng,repo,wditem,'stripalbum','stripalbum van ','P179',MultiLanguage,False)
          placefound='strip'
      elif type_of_item=='Q207628': #compositie van P86
        if (orig_desc in ['compositie','']):
          my_description,missing = its_a_composition(lng,repo,wditem)
          placefound='compositie'
      elif type_of_item=='Q95074':  #personage uit P1080
        if (orig_desc in ['personage','']):
          my_description,missing=its_a_fictional_character(lng,repo,wditem);
          placefound='personage'
      elif type_of_item=='Q42032':  #ccTLD top level domain van P17
        if (orig_desc in ['top level domain','toplevel domain','']):
          pass
          placefound='ccTLD'
      elif type_of_item=='Q106658':  #Landkreis in P131
        if (orig_desc in ['landkreis','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'Landkreis in')
          placefound='landkreis'
      elif type_of_item=='Q571': #boek van P50
        if (orig_desc in ['','boek','book']):
          my_description,missing = its_a_book(lng,repo,wditem)
          placefound='boek'
      elif type_of_item=='Q134556':  #single van P175
        if (orig_desc in ['','single','nummer','plaat']):
          my_description,missing = its_a_single(lng,repo,wditem)
          placefound='single'
      elif type_of_item=='Q7302866':  #single van P175
        if (orig_desc in ['','single','nummer','plaat']):
          my_description,missing = its_a_nummer(lng,repo,wditem)
          placefound='nummer'
      elif type_of_item=='Q2912397': #eendagswielerwedstrijd in P17
        if (orig_desc in ['eendaagse wielerwedstrijd','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'eendaagse wielerwedstrijd in ',True)
          placefound='1dagswielerkoers'
      elif type_of_item=='Q355304': #watergang
        if (orig_desc in ['','watergang']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'watergang in ',True)
          placefound='watergang'
      elif type_of_item=='Q34763': #schiereiland
        if (orig_desc in ['schiereiland','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'schiereiland in ',True)
          placefound='schiereiland'
      elif type_of_item=='Q23442':
        if (orig_desc in ['eiland','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'eiland in ',True)
          placefound='eiland'
      elif type_of_item=='Q16970': #kerkgebouw
        if (orig_desc in ['kerkgebouw','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'kerkgebouw in ',True)
          placefound='kerkgebouw'
      elif type_of_item=='Q23925393': #douar
        if (orig_desc in ['douar','']):    
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'douar in',True)
          placefound='douar'
      elif type_of_item=='Q165':
        if (orig_desc in ['zee','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'zee in ',True)
          placefound='zee'
      elif type_of_item=='Q102496':
        if (orig_desc in ['parochie','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'parochie in ',True)
          placefound='parochie'
      elif type_of_item=='Q9842':
        if (orig_desc in ['basisschool','basisschool in italië','']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,u'basisschool in ')
          placefound='basisschool'
      elif type_of_item=='Q3914':
        if (orig_desc in ['school','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'school in ',True)
          placefound='school'
      elif type_of_item=='Q273057': #discografie   
        if (orig_desc in ['','discografie']):
          my_description,missing = its_a_discography(lng,repo,wditem)
          placefound='discografie'
      elif type_of_item=='Q3966183': #Pokémonwezen 
        if (orig_desc in [u'Pokemonwezen',u'Pokémon-wezen','Pokemon',u'Pokémon','']):
          my_description = u'Pokémonwezen'
          missing = ''
          placefound='Pokemonwezen'
      elif type_of_item=='Q5633421': #wetenschappelijk tijdschrift
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'wetenschappelijk tijdschrift','wetenschappelijk tijdschrift van ','P123',False)
        if (orig_desc in ['','tijdschrift','wetenschappelijk tijdschrift']) or (prev_desc==orig_desc): 
          my_description,missing = its_a_generalthing(lng,repo,wditem,'wetenschappelijk tijdschrift','wetenschappelijk tijdschrift van ','P123',MultiLanguage,False)
          placefound='wetenschappelijk tijdschrift'
      elif type_of_item=='Q202444':
        if (orig_desc in ['voornaam','']):
          my_description,missing=its_a_firstname(lng,repo,wditem)
          placefound='voornaam'
      elif type_of_item=='Q101352': #achternaam
        if (orig_desc in ['','']):
          my_description='achternaam'
          missing=''
          placefound='achternaam'
      elif type_of_item=='Q4167836':
        if (orig_desc in ['','categorie','Categorie','category']):
          my_description='Wikimedia-categorie'
          missing=''
          placefound='categorie'
      elif type_of_item=='Q3863': #planetoide
        if (orig_desc in ['']):
          my_description=u'planetoïde'
          placefound='planetoide'
      elif type_of_item=='Q13442814':
        if (orig_desc in ['artikel','']):
          my_description='wetenschappelijk artikel'
          placefound='wetenschappelijk artikel'
      elif type_of_item=='Q2039348': #Nederlandse gemeente
        if (orig_desc in ['gemeente','Nederlandse gemeente','gemeente in Nederland','']):
          pass
          placefound='Nederlandse gemeente'
      elif type_of_item=='Q5864':
        if (orig_desc in ['geile dwerg','']):
          my_description = 'gele dwerg'
          placefound='gele dwerg' 
      elif type_of_item=='Q50231':
        if (orig_desc in ['bestuurlijk gebied','gebied','']):
          my_description = 'bestuurlijk gebied in China'
          placefound='geo van China'
      elif type_of_item=='Q5084':  #gehucht
        if (orig_desc in ['gehucht','']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,'gehucht in')
          placefound='gehucht'
      elif type_of_item=='Q55488':
        if (orig_desc in ['spoorwegstation','']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,'spoorwegstation in')
          placefound='spoorwegstation'
      elif type_of_item=='Q735428':
        if (orig_desc in ['gemeente','']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,'gemeente in')
          placefound='gemeente in China'
          #print('[%s][%s]'%(my_description,missing))
      elif type_of_item=='Q2526255': # filmregisseur
        if (orig_desc in ['filmregisseur','','regisseur']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'filmregisseur uit',True)
          placefound='filmregisseur'
      elif type_of_item=='Q34442': #weg
        if (orig_desc in ['weg','straat','straat in','']):
          my_description,missing= its_something_in_a_country(lng,repo,wditem,'weg in',True)
          placefound = 'weg'
      elif type_of_item=='Q985488':
        if (orig_desc in ['bewonersgemeenschap','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'bewonersgemeenschap in',True)
          placefound='bewonersgemeenschap'
      elif type_of_item=='Q23397':
        if (orig_desc in ['meer','']):
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'meer in',True)
          placefound='meer'
      elif type_of_item=='Q2996394':
        if (orig_desc in ['x','']):
          my_description = 'biologisch proces'
          placefound='biologisch proces'
      elif type_of_item=='Q14860489':
        if (orig_desc in ['y','']):
          my_description = 'moleculaire functie'
          placefound='mol.func'
      elif type_of_item=='Q5058355':
        if (orig_desc in ['z','']):
          my_description = 'cellulaire component'
          placefound='cel.comp'
      elif type_of_item=='Q1077097':
        if (orig_desc in ['tambon','']):
          its_a_tabon_in_thailand(lng,repo,wditem)
          placefound='tambon'
      elif type_of_item=='Q4592255':
        if (orig_desc in ['','']):
          my_description = 'project sub-pagina'
          placefound='pr.sub'
      elif type_of_item=='Q7366': #lied
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'lied','lied van ','P175',False)
        if (orig_desc in ['lied','']) or (prev_desc==orig_desc):
          my_description,missing = its_a_generalthing(lng,repo,wditem,'lied','lied van ','P175',MultiLanguage,False)
          placefound='lied'
      elif type_of_item=='Q21278897':
        if (orig_desc in ['','']):
          my_description = 'Wiktionary-doorverwijzing'
          placefound='wikt.redirect'
      elif type_of_item=='Q17329259': #encyclopedisch artikel
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'encyclopedisch artikel','encyclopedisch artikel uit ','P1433',False)
        if (orig_desc in ['encyclopedisch artikel','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'encyclopedisch artikel','encyclopedisch artikel uit ','P1433',MultiLanguage,False)
          placefound='ency-art'
      elif type_of_item=='Q620615': #mobiele app
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'mobiele app','mobiele app van ','P178',False)
        if (orig_desc in ['mobiele app','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'mobiele app','mobiele app van ','P178',MultiLanguage,False);
          placefound='x'
      elif type_of_item=='Q1004':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'stripverhaal','stripverhaal van ','P179',False)
        if (orig_desc in ['stripverhaal','']) or (prev_desc==orig_desc):
          my_description,missing = its_a_generalthing(lng,repo,wditem,'stripverhaal','stripverhaal van ','P179',MultiLanguage,False)
          placefound='stripverhaal'
      elif type_of_item=='Q14406742':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'stripreeks','stripreeks door ','P50',False)
        if (orig_desc in ['stripreeks','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'stripreeks','stripreeks door ','P50',MultiLanguage,False)
          placefound='stripreeks'
      elif type_of_item=='Q737498': #academisch tijdschrift
        if (orig_desc in ['tijdschrift','']):
          my_description='academisch tijdschrift'
          placefound='academisch tijdschrift'
      elif type_of_item=='Q24764':
        if (orig_desc in ['gemeente','']):
          my_description='Filipijnse gemeente'
          placefound='filip-gem'
      elif type_of_item=='Q70208':
        if (orig_desc in ['gemeente','']):
          my_description='Zwitserse gemeente'
          placefound='zwits-gem'
      elif type_of_item=='Q127448':
        if (orig_desc in ['gemeente','zweedse gemeente']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'Zweedse gemeente in')
          placefound='zwe-gem'
      elif type_of_item=='Q203300':
        if (orig_desc in ['gemeente','']):
          my_description='gemeente in Liechtenstein'
          placefound='licht-gem'
      elif type_of_item=='Q54050': 
        if (orig_desc in ['','heuvel','heuvel in','heuvel in noorwegen','heuvel in albanie','heuvel in albanië','heuvel in australie','heuvel in australië','heuvel in mexico','heuvel in nederland','heuvel in marokko','heuvel in duitsland',
                          'zuid-afrika','','','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'heuvel in')
          placefound='heuvel'
      elif type_of_item=='Q166735': #broekbos
        if (orig_desc in ['broekbos','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'broekbos in')
          placefound='broekbos'
      elif type_of_item=='Q7075':
        if (orig_desc in ['bibliotheek','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'bibliotheek in')
          placefound='bieb'
      elif type_of_item=='Q50386450': #opera-personage
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'opera-personage','opera-personage uit ','P1441',False)
        if (orig_desc in ['opera-personage','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'opera-personage','opera-personage uit ','P1441',MultiLanguage,False)
          placefound='opera-personage'
      elif type_of_item=='Q21014462': #cel lijn
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'cellijn','cellijn van een ','P703',False)
        if (orig_desc in ['cellijn','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'cellijn','cellijn van een ','P703',MultiLanguage,False)
          placefound='cellijn'
      elif type_of_item=='Q178122':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'aria','aria van ','P86',False)
        if (orig_desc in ['aria','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'aria','aria van ','P86',MultiLanguage,False)
          placefound='aria'
      elif type_of_item=='Q3331189':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'uitgave','uitgave van ','P50',False)
        if (orig_desc in ['uitgave','editie','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'uitgave','uitgave van ','P50',False,False)
          placefound='uitgave'
      elif type_of_item=='Q1344':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'opera','opera van ','P86',False)
        if (orig_desc in ['opera','']) or (orig_desc==prev_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'opera','opera van ','P86',MultiLanguage,True)
          placefound='opera'
      elif type_of_item=='Q53764738':
        if (orig_desc in ['','']):
          my_description = 'Chinees karakter'
          placefound='chinees karakter'
      elif type_of_item=='Q79007':
        if (orig_desc in ['straat','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'straat in')
          placefound='straat'
      elif type_of_item=='Q27020041':
        if (orig_desc in ['sportseizoen','sportseizoen van een competitie','']):
          my_description,missing=its_a_sports_season(lng,repo,wditem)
          placefound='sportseizoen'
      elif type_of_item=='Q15991303':
        if (orig_desc in ['voetbalcompetitie','']):
          my_description, missing=its_something_in_a_country(lng,repo,wditem,'voetbalcompetitie in',True)
          placefound='voetbalcompetitie'
      elif type_of_item=='Q742421':
        if (orig_desc in ['','theatergezelschap']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'theatergezelschap uit',True)
          placefound='theatergezelschap'
      elif type_of_item=='Q4022':
        if (orig_desc in ['rivier','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'rivier in',True)
          placefound='rivier'
      elif type_of_item=='Q12323':
        if (orig_desc in ['dam','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'dam in')
          placefound='dam'
      elif type_of_item=='Q30198':
        if (orig_desc in ['','uitstekend landdeel','meers','moeras']) or (orig_desc[:19]=='uitstekend landdeel'):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'moeras in')
          placefound='uitstekend landdeel'
      elif type_of_item=='Q22698':
        if (orig_desc in ['park','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'park in')
          placefound='park'
      elif type_of_item=='Q2042028':
        if (orig_desc in ['kloof','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'kloof in')
          placefound='kloof'
      elif type_of_item=='Q131681':
        if (orig_desc in ['stuwmeer','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'stuwmeer in')
          placefound='stuwmeer'
      elif type_of_item=='Q4421':
        if (orig_desc in ['bos','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'bos in')
          placefound='bos'
      elif type_of_item=='Q953806':
        if (orig_desc in ['bushalte','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'bushalte in')
          placefound='bushalte'
      elif type_of_item=='Q751876':
        if (orig_desc in ['kasteel','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'kasteel in')
          placefound='kasteel'
      elif type_of_item=='Q4502142':
        if (orig_desc in ['visueel kunstwerk','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'visueel kunstwerk','visueel kunstwerk in collectie ','P195',MultiLanguage,False)
          placefound='visueel kunstwerk'
      elif type_of_item=='Q732577':
        if (orig_desc in ['publicatie','']):
          my_description,missing=its_a_publication(lng,repo,wditem)
          placefound='publicatie'
      elif type_of_item=='Q55659167':
        if (orig_desc in ['','natuurlijke waterloop']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'natuurlijke waterloop in',NoCheckFilled)
          placefound='natuurlijke waterloop'
      elif type_of_item=='Q41176':
        if (orig_desc in ['gebouw','bouwwerk','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'gebouw in')
          placefound='gebouw'
      elif type_of_item=='Q5783996':
        if (orig_desc in ['cottage','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'cottage in')
          placefound='cottage'
      elif type_of_item=='Q3947':
        if (orig_desc in ['woonhuis','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'woonhuis in')
          placefound='woonhuis'
      elif type_of_item=='Q191067':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'redactioneel artikel','redactioneel artikel in ','P1433',False)
        if (orig_desc in ['redactioneel artikel','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'redactioneel artikel','redactioneel artikel in ','P1433',MultiLanguage,True)
          placefound='redactioneel artikel'
      elif type_of_item=='Q13141064':
        if (orig_desc in ['','badmintonner','badmintonspeler','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'badmintonspeler uit',)
          placefound='badmintonspeler'
      elif type_of_item=='Q26703203':
        if (orig_desc in ['stolperstein','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'stolperstein in')
          placefound='stolperstein'
      elif type_of_item=='Q8054':
        prev_desc,missing=it_was_a_generalthing(lng,repo,wditem,'proteïne','proteïne in ','P702',False)
        if (orig_desc in ['proteine','proteïne','protein','']) or (prev_desc==orig_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'proteïne','proteïne in ','P703',MultiLanguage,True)
          placefound='proteine'
      elif type_of_item=='Q7187':
        prev_desc=it_was_a_generalthing(lng,repo,wditem,'gen','gen in', 'P703',MultiLanguage)
        if (orig_desc in ['gen','']) or (orig_desc==prev_desc):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'gen','gen in ','P703',MultiLanguage,(orig_desc==prev_desc)) #fixing
          if (missing==txt2skip) and (my_description==''): my_description='gen'
          print(f'<{my_description}>[{missing}]---<{prev_desc}>')
          placefound='gen'
        else:
          print(f'{wditem.title()}-{prev_desc}')
      elif type_of_item=='Q30612':
        if (orig_desc in ['klinisch onderzoek','']):
          my_description='klinisch onderzoek'
          placefound='klinisch onderzoek'
      elif type_of_item=='Q56436498':
        if (orig_desc in ['','dorp in india',' ']):
          my_description,missing = its_something_in_an_entity(lng,repo,wditem,'dorp in')
          if (my_description in ['',' ']):
            my_description='dorp in India'
            missing=''
          placefound='dorp in India'
      elif type_of_item=='Q811979':
        if (orig_desc in ['bouwwerk','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'bouwwerk in')
          placefound='bouwwerk'
      elif type_of_item=='Q277338':
        if (orig_desc in ['pseudogen','gen','speudogen','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'pseudogen','pseudogen in ','P703',MultiLanguage,False)  #P1057 #fixed
          placefound='pseudogen'
      elif type_of_item=='Q126807':
        if (orig_desc in ['kleuterschool','school','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'kleuterschool in')
          placefound='kleuterschool'
      elif type_of_item=='Q39614':
        if (orig_desc in ['begraafplaats','','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'begraafplaats in')
          placefound='begraafplaats'
      elif type_of_item=='Q14660':
        if (orig_desc in ['vlag','']):
          pass
          my_description,missing=its_a_generalthing(lng,repo,wditem,'vlag','vlag van jurisdictie ','P1001',MultiLanguage,False)
          placefound='vlag'
      elif type_of_item=='Q6451276':
        if (orig_desc in ['CSR-rapport','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'CSR-rapport','CSR-rapport over ','P921',MultiLanguage,False)
          placefound='CSR-rapport'
      elif type_of_item=='Q2668072':
        if (orig_desc in ['','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'collectie','collectie uit ','P195',MultiLanguage,False)
          placefound='collectie'
      elif type_of_item=='Q17633526':
        if (orig_desc in ['','']):
          my_description='Wikinews-artikel'
          missing=''
          placefound='wikinews-artikel'
      elif type_of_item=='Q57733494':
        if (orig_desc in ['','badmintoernooi']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'badmintontoernooi in',False)
          placefound='badmintontoernooi'
      elif type_of_item=='Q726242':
        if (orig_desc in ['','RR Lyrae-ster']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'RR Lyrae-ster','RR Lyrae-ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='RR Lyrae-ster'
      elif type_of_item=='Q2065704': #tingrett
        if (orig_desc in ['','kantongerecht','kantongerecht in noorwegen']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'kantongerecht in',NoCheckFilled)
          placefound='tingrett'
      elif type_of_item=='Q1457376':
        if (orig_desc in ['','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'overlappende dubbelster','overlappende dubbelster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='overlappende dubbelster'
      elif type_of_item=='Q1149652':
        if (orig_desc in ['','district']):
          my_description='district in India'
          placefound='district in India'
      elif type_of_item=='Q13005188':
        if (orig_desc in ['','mandal','mandal in India']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'mandal in')
          placefound='mandal'
      elif type_of_item=='Q19389637':
        if (orig_desc in ['biografisch artikel','']) or (orig_desc.find('biografisch artikelvan')==0):
          #my_description,missing='biografisch artikel',''
          my_description,missing=its_a_generalthing(lng,repo,wditem,'biografisch artikel','biografisch artikel van','P2093',MultiLanguage,False)
          if (missing!=''):
            my_description,missing=its_a_generalthing(lng,repo,wditem,'biografisch artikel','biografisch artikel uit','P1433',MultiLanguage,False)
          placefound='biografisch artikel'
      elif type_of_item=='Q1931185':
        if (orig_desc in ['','']):
          my_description='radiobron'
          placefound='radiobron'
      elif type_of_item=='Q2154519':
        if (orig_desc in ['','']):
          my_description='bron van astrofysische röntgenstraling'
          placefound='rontgenbron'
      elif type_of_item=='Q67206701':
        if (orig_desc in ['','']):
          my_description='ver-liggend infrarood object'
          placefound='IR-far'
      elif type_of_item=='Q11812394':
        if (orig_desc in ['','theaterbedrijf']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'theaterbedrijf in',CheckFilled)
          placefound='theater'
      elif type_of_item=='Q83373':
        if (orig_desc in ['','']):
          my_description='quasar'
          placefound='quasar'
      elif type_of_item=='Q189004':
        if (orig_desc in ['','']):
          my_description='onderwijsinstelling'
          placefound='college'
      elif type_of_item=='Q15917122':
        if (orig_desc in ['roterende variabele ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'roterende variabele ster','roterende variabele ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='rot.var.ster'
      elif type_of_item=='Q204194':
        if (orig_desc in ['absorptienevel','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'absorptienevel','absorptienevel in sterrenbeeld','P59',MultiLanguage,False)
          placefound='absorptienevel'
      elif type_of_item=='Q71963409':
        if (orig_desc in ['compacte groep van sterrenstelsels','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'compacte groep van sterrenstelsels','compacte groep van sterrenstelsels in sterrenbeeld','P59',MultiLanguage,False)
          placefound='compacte groep sterrenstelsels'
      elif type_of_item=='Q66619666':
        if (orig_desc in ['rode reuzentak-ster','rode reuzentak-ster in sterrenbeeld']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'rode reuzentak-ster','rode reuzentak-ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='rode reuzentak-ster'
      elif type_of_item=='Q130019':
        if (orig_desc in ['koolstofster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'koolstofster','koolstofster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='koolstofster'
      elif type_of_item=='Q72802508':
        if (orig_desc in ['emissielijn-sterrenstelsel','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'emissielijn-sterrenstelsel','emissielijn-sterrenstelsel in sterrenbeeld','P59',MultiLanguage,False)
          placefound='emissielijn-sterrenstelsel'
      elif type_of_item=='Q1332364':
        if (orig_desc in ['roterende ellipsoide ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'roterende ellipsoide ster','roterende ellipsoide ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='rot.ell.ster'
      elif type_of_item=='Q72803622': 
        if (orig_desc in ['emissie-lijn-ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'emissie-lijn-ster','emissie-lijn-ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='emissie-lijn-ster'
      elif type_of_item=='Q88965416':
        if (orig_desc in ['','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'Zweedse schooleenheid in')
          placefound='se-school'
      elif type_of_item=='Q6243':
        if (orig_desc in ['veranderlijke ster','']):
          my_description,missing=its_a_generalthing(lng,repo,wditem,'veranderlijke ster','veranderlijke ster in sterrenbeeld','P59',MultiLanguage,False)
          placefound='verand.ster'
      elif type_of_item=='Q1690211':
        if (orig_desc in ['','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'openbare wasplaats in')
          placefound='openb.waspl'
      elif type_of_item=='Q5358913':
        if (orig_desc in ['','']):
          my_description,missing=its_something_in_an_entity(lng,repo,wditem,'Japanse basisschool in')
          placefound='jap.bas.sch'
      elif type_of_item=='Q3508250':
        if (orig_desc in ['','']):
          my_description,missing=its_a_headquarted_thing(lng,repo,wditem,'syndicat intercommunal in')
          placefound='synd.intercomm'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif type_of_item=='Q':
        if (orig_desc in ['','']):
          pass
          placefound='x'
      elif my_description=='':
        #log_unknown(False,'%s|%s|%s',wditem.title(),type_of_item,en_description)
        placefound='unknown: %s' %type_of_item
        if (not commit):
          print('type of item: %s, orig_desc: [%s], new: [%s]' % (type_of_item,orig_desc,my_description))

          
          
          
          
      if (((my_description!='') and (missing!=txt2skip)) or not(lng in wditem.labels)) and (my_description.find('n/a')==-1):  
        newlabel = u''
        try :
          data = {}
          if not (lng in wditem.labels):
            if (type_of_item in update_label_allowed):
              if (lng in wditem.labels):  #use link-name of same lng as label 
                newlabel=wditem.labels[lng]
                data.update({'labels': { lng: newlabel }})
              else:
                for trylng in lng_canbeused:
                  if trylng in wditem.labels: #same lng is not there, use en-wiki instead
                    mylabel = wditem.labels[trylng]
                    if (',' in mylabel):
                      pass #don't use this label, there are unacceptable characters in the label
                    elif ('(' in mylabel):
                      mylabel = mylabel[0:mylabel.index('(')]
                    data.update({'labels': { lng: mylabel }})
                    newlabel=mylabel #to put in logfile
                    break  #found, leave for-loop
              
          if (my_description!='') and (missing!=txt2skip):
            data.update( {'descriptions': {lng:my_description}} )
          if skiplog:
            if ((my_description=='') and (orig_desc=='') and (missing!=txt2skip) and gotP31):
              log_skipped(type_of_item)
          if data!={}:
            items_written += 1
            if commit:
              wditem.editEntity(data,summary=f'nl-description, [[User:Edoderoobot/Set-nl-description|python code]] - {placefound}')
              totaledits+=1
              print('Written %d-%s' % (lend(data),data))
              if (newlabel=='') and (my_description==''):
                pass
              else:
                logme(False, '%s|%s|%s|%s|%s|%s|%s',datetime.now().strftime("%Y-%b-%d/%H:%M:%S"),wditem.title(),lng,newlabel,orig_desc,my_description,placefound)
            else:
              print('No commit, item not changed: %s - data=[%s]' % (wditem.title(),data))
        except ValueError:
          log_unknown(False, "ValueError occured on %s",wditem.title())
        except :
          log_unknown(False, "Undefined error occured on %s-[%s]",wditem.title(),missing)
          pass
        else :
          pass #print("Else:")

        items_found += 1


    return items_found,items_written






def lastXnewpages(maxp):
  print('Begonnen')
  site=pywikibot.Site(run_lng)
  mygenerator=pg.NewpagesPageGenerator(site,0,maxp)
  for onepage in mygenerator:
    if (onepage.exists()): #avoid speedy deleted 
      #print('p:%s' % onepage.title())
      if ('wikibase_item' in onepage.properties()):
       try:
        wd=onepage.data_item()  
        wd.get(get_redirect=True)
        yield(wd)
       except:
        pass
  print('Klaar')

def testrun():  
 global output2screen
 output2screen = True
 repo = pywikibot.Site().data_repository()
 item2get = 'Q92924911' 
 
 x = pywikibot.ItemPage(repo, item2get)
 x.get(get_redirect=True) 
 print('read item')
 if x.exists():
   print('item does exist')
   found,written = action_one_item('nl',repo,x)
   #print('[%s][%s]' % (x.descriptions['nl'],''))
 else:
   print('no action!') 

def wd_one_without_description(item):
  base_sparql = 'SELECT ?item WHERE {?item wdt:P31 wd:%s . OPTIONAL {?item schema:description ?itemdescription filter (lang(?itemdescription) = \"nl\").  } FILTER (!BOUND(?itemdescription))}' 
  one_sparql = base_sparql % item
  for wditem in wd_sparql_query(one_sparql):
    if (wditem.exists()):
      yield wditem

def wd_all_without_description():
  base_sparql = 'SELECT ?item WHERE {?item wdt:P31 wd:%s . OPTIONAL {?item schema:description ?itemdescription filter (lang(?itemdescription) = \"nl\").  } FILTER (!BOUND(?itemdescription))}'
  for item in all_types_list:
    wd_one_without_description(item)    
    """
    one_sparql = base_sparql % item
    for wditem in wd_sparql_query(one_sparql):
      if (wditem.exists()):
        yield wditem
    """
    
def wd_all_simple_P131():
  for onesimpleitem in simple_set_byP131:
    query = 'select ?item where {?item wdt:P31 wd:%s}' % onesimpleitem
    print('\n\nQuery: %s\n\n' % query)
    for oneitem in wd_sparql_query(query):
      try:
        if oneitem.exists():
          oneitem.get(get_redirect=True)
          yield oneitem
          #action_one_P131_item()
        else:
          print('Else wd-simple: %s' % oneitem.title())        
          pass
      except:
        pass      
  yield u'Q5'
     
     
def wd_all_countries(spq):
  country_query = 'select ?item where {?item wdt:P31 wd:Q6256}'
  country_generator = wd_sparql_query(country_query)
  for wd_country in country_generator:
    spq_with_country = spq % wd_country.title()
    one_country_generator = wd_sparql_query(spq_with_country)
    for item in one_country_generator:
        if (item.exists()):
          item.get(get_redirect=True)
          yield item
 
def wd_sparql_query(spq):
  wikidatasite=pywikibot.Site('wikidata','wikidata') 
  generator=pg.WikidataSPARQLPageGenerator(spq,site=wikidatasite)
  for wd in generator:
    if (wd.exists()):
      wd.get(get_redirect=True)
      yield wd
  
def wd_from_file(usefilename):
  repo=pywikibot.Site('wikidata','wikidata').data_repository()
  csvfile=open(usefilename,'r')
  for alllines in csvfile:
    qitem=alllines[alllines.find('Q'):alllines.find(',')]
    if (len(qitem)>0):
      wditem=pywikibot.ItemPage(repo,qitem)
      wditem.get(get_redirect=True)
      yield wditem

def wd_user_edits(username,ucsite,totaledits):
  repo=pywikibot.Site('wikidata','wikidata').data_repository()
  useredits=pg.UserContributionsGenerator(username,site=ucsite,total=totaledits,namespaces=[0])      
  for oneedit in useredits:
    oneedit.get(get_redirect=True)
    if (oneedit.exists()):
      wd=pywikibot.ItemPage(repo,oneedit.title())
      wd.get(get_redirect=True)
      if (wd.exists()):
        yield wd

def sparql_nodescription(sparql):
  return 'select distinct ?item where {{%s}filter (!bound(?itemDescription))}' % sparql  
 
def some_items():
  repo=pywikibot.Site('wikidata','wikidata').data_repository()
  do_these=['Q52504095','Q52501574']  #scenografino / dramaturgino
  do_these=['Q62507873','Q62898370']  #null edits
  for one_item in do_these:
    wd=pywikibot.ItemPage(repo,one_item)
    wd.get(get_redirect=True)
    if (wd.exists()):
      yield wd

def newest_items(repo,site):
    for item in pg.NewPagesPageGenerator(site):
        break
    startno=int(item.title()[1:])
    for itemno in range(startno,0,-1):
        item=pywikibot.ItemPage(repo,'Q%d'%itemno)
        yield(item)
    
    
def generator_last_hour():
    timenow=None
    site=pywikibot.Site('wikidata','wikidata')
    repo=site.data_repository()
    generator=newest_items(repo,site);
    generator=pg.NewpagesPageGenerator(site)
    for item in generator:
      if timenow==None:
        timenow=item.oldest_revision.timestamp
        endtime=timenow-timedelta(1.0/24.0);
        untilltime=endtime-timedelta(0.001);
      if (item.oldest_revision.timestamp > untilltime):
        #print(item.title())
        item=pywikibot.ItemPage(repo,item.title())
        item.get(get_redirect=True)
        if (item.exists()):
          #print(item.title())
          yield item
      else:
        print(f'Klaar: {item.oldest_revision.timestamp}' )
        break

 
def main(debug=False):
    maxwrites=1
    print ("main")
    global mailmessage
    pigenerator=None
    
    """
    query = default_query #later, I want to manage this with params
    sparql_query = u'SELECT ?item WHERE {   ?item wdt:P31 wd:Q21191270 .   ?item wdt:P179 ?dummy0 . }'
    sparql_query = u'select ?item where{{select ?item ?itemLabel ?itemDescription WHERE {   ?item wdt:P31 wd:Q21191270 .   ?item wdt:P179 ?dummy0 . {service wikibase:label{bd:serviceParam wikibase:language "nl" . }}}} filter (!bound(?itemDescription))}'
    
    
    #sparql_query=sparql_nodescription(sparql_query)
    sparql_query=u'SELECT ?item WHERE { ?item wdt:P31 wd:Q5 . ?item wdt:P106 ?dummy0 . ?wiki0 <http://schema.org/about> ?item . ?wiki0 <http://schema.org/isPartOf> <https://nl.wikipedia.org/> }'  #claim[31:5] and claim[106] and link[nlwiki]

    sparql_query = u'select * {{SELECT ?item ?itemDescription WHERE {{ ?item wdt:P31 wd:Q4167836 }  service wikibase:label{bd:serviceParam wikibase:language "nl" . }  }}}'

    """
    query = u'link[nlwiki]'  
    sparql_query = u'SELECT * {{SELECT ?item WHERE { ?wiki0 <http://schema.org/about> ?item . ?wiki0 <http://schema.org/isPartOf> <https://nl.wikipedia.org/> {service wikibase:label{bd:serviceParam wikibase:language "nl" . }}}} filter (!bound(?itemDescription))}   '
    sparql_query = u'SELECT * {{SELECT ?item WHERE { ?wiki0 <http://schema.org/about> ?item . ?wiki0 <http://schema.org/isPartOf> <https://nl.wikipedia.org/> }} }   '
    """    
    query = u'claim[31:8502] and claim[17]'
    sparql_query=u'select * where {{ SELECT ?item  WHERE { ?item wdt:P31 wd:Q8502 . ?item wdt:P17 ?dummy0 {service wikibase:label{bd:serviceParam wikibase:language "nl" . }}}} filter (!bound(?itemDescription))}'
    """
    
    #sparql_query = u'SELECT ?item WHERE {{SELECT ?item WHERE {hint:Query hint:optimizer "None" .{SELECT ?item WHERE {?item wdt:P31 wd:Q4167836 .} LIMIT 275000}OPTIONAL { ?item schema:description ?itemDescription  }filter (!bound(?itemDescription)) }} SERVICE wikibase:label {  bd:serviceParam wikibase:language "nl" .  }}'
    #sparql_query=sparql_nodescription('select ?item where {?item wdt:P31 wd:Q5633421. OPTIONAL { ?item schema:description ?itemDescription  } }')
    #sparql_query='select ?item where {?item wdt:P31 wd:Q202444 }'
    sparql_query='select ?item where {?item wdt:P31 wd:Q5633421 }'
    #
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q13442814 .     ?item wdt:P577 ?published .     filter ((?published > "1800-01-01T00:00:00Z"^^xsd:dateTime) && (?published < "2000-01-01T00:00:00Z"^^xsd:dateTime)) }'
    #sparql_query='SELECT ?item WHERE {?item wdt:P27 wd:%s . ?item wdt:P31 wd:Q5 . ?item wdt:P106 ?beroep optional { ?item schema:description ?itemDescription . FILTER(lang(?itemDescription)="nl") } .  FILTER (REGEX(STR(?itemDescription), "n[/]a", "i"))}'
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q207628 . OPTIONAL {?item schema:description ?itemdescription filter (lang(?itemdescription) = \"nl\").  } FILTER (!BOUND(?itemdescription))} '  #church no description
    #sparql_query='select ?item where {?item wdt:P31 wd:Q207628}'
    #sparql_query='select ?item where {?item wdt:P31 wd:Q5 . ?item wdt:P106 ?beroep . ?item wdt:P27 wd:%s . {service wikibase:label{bd:serviceParam wikibase:language "nl" . }} OPTIONAL { ?item schema:description ?d .  FILTER(lang(?d)="nl") } filter (!bound(?d))}'
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q3184121 . ?item wdt:P17 wd:%s}'  #basisschool per land
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q1077097 }'
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q985488}' #bewonersgemeenschap in ?land
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q4830453}' #onderneming
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q21278897}' #doorverwijzing naar wiktionary
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q5084}' #gehucht -> test
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q55488}' #spoorwegstation -> test
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q43229}' #organisatie
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q17329259}' #encyclopedsich artikel
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q207628}' #
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q23397}' #meer 
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q1004 }' #stripverhaal
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q14406742 . }' #stripreeks
    #sparql_query='select ?item where {?item wdt:P31 wd:Q34442 . ?item wdt:P17 ?land}' #weg in land
    #sparql_query='select ?item where {?item wdt:P31 wd:Q273057}' #discografie
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q486972 . ?item wdt:P17 wd:%s}'  #nederzetting per land
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q101352} ' #achternaam
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q7366}' #lied
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q5. ?item wdt:P106 wd:Q2526255}' #filmregisseur
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q15416}' #televisieprogramma
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q134556}' #single
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q3305213}' #3. schilderij
    #sparql_query='SELECT ?item where {?item wdt:P31 wd:Q4167410 . ?item wdt:P17 ?land}' #disambiguation-page
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q1539532}' #sportseizoen -> pass
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q737498}' #academisch tijdschrift
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q166735}' #broekbos
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q54050}' #heuvel
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q253019}' #ortsteil
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q7075}' #bibliotheek
    
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q21014462}' #cel lijn 100.000++
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q5 . ?item wdt:P106 wd:Q1028181 . ?item wdt:P27 ?land}'  #kunstschilders geboren in een land
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q178122}'  #aria
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q3331189}' #2d2 #uitgave van P50
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q1344}'     #3d3 #opera van P86

    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q742421}' #theatergezelschap
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q4022}' #rivier
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q180684}' #conflict
    ##sparql_query='select distinct ?item where {?item wdt:P31 wd:Q571 . ?item wdt:P50 ?auteur}' #boek met auteur
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q732577 . ?item wdt:P123 ?itsthere}' #badmintonners
    #sparql_query='select ?item where {  ?item wdt:P31 wd:Q5 .   ?item wdt:P106 wd:Q639669 .   ?item wdt:P27 ?land . }' #zwemmers
    #sparql_query='select ?item where {  ?item wdt:P31 wd:Q5 .   ?item wdt:P106 ?beroep .   ?item wdt:P27 wd:Q183 . }' #belgen met een beroep
    #sparql_query='SELECT ?item WHERE {{select ?constellation where {?constellation wdt:P31 wd:Q8928}}?item wdt:P31 wd:Q318 . ?item wdt:P59 ?constellation }' #galaxy
     
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q5783996}' #cottage
    #sparql_query='select ?item where {?item wdt:P31 wd:Q3863}'    #planetoide
    #sparql_query='select ?item where {?item wdt:P31 wd:Q726242}' #LLYR-ster
    #sparql_query='SELECT * { ?item schema:description "onderzoeker"@nl . ?item wdt:P27 wd:%s }'
    #sparql_query='SELECT * { ?item schema:description "tennisser"@nl . ?item wdt:P27 ?land}' #
    #sparql_query='SELECT ?item WHERE {?item wdt:P31 wd:Q3947}' #
    #sparql_query='select ?item ?land where { ?item wdt:P31 wd:Q5. ?item wdt:P106 wd:Q1650915. ?item wdt:P27 ?land.}'
    #sparql_query='SELECT ?item {?item wdt:P31 wd:Q13442814 . OPTIONAL { ?item schema:description ?d . FILTER(lang(?d)="nl") }  FILTER( !BOUND(?d) )} LIMIT 1000'
    #sparql_query=u'SELECT ?item WHERE { ?item wdt:P31 wd:Q5 . ?item wdt:P106 ?dummy0 . ?wiki0 <http://schema.org/about> ?item . ?wiki0 <http://schema.org/isPartOf> <https://nl.wikipedia.org/> {service wikibase:label{bd:serviceParam wikibase:language "nl" . }}}'  #claim[31:5] and claim[106] and link[nlwiki]
    #sparql_query='select ?item where {?item wdt:P31 wd:Q19389637}' #biografisch artikel
    sparql_query='select ?item where {?item wdt:P31 wd:Q3508250}' #
    site=pywikibot.Site('wikidata','wikidata')
    repo=site.data_repository()

    items_processed=0

    lng = run_lng
    if debug: print("main-1")


    if (True):
      #pigenerator = wd_from_file('/stack/query.csv')
      #pigenerator = wd_all_countries(sparql_query)
      #pigenerator = wd_all_without_description()
      #pigenerator=wd_one_without_description('Q189004')  #onderwijsinstelling
      #pigenerator = wd_all_simple_P131()
      #pigenerator = wd_user_edits('Edoderoobot',site,511111)
      #pigenerator = wd_all_items(1)
      #pigenerator = lastXnewpages(1999999) #max one month of newpages anyways

      #pigenerator = wd_all_items(-1)
      #pigenerator=some_items()
      pigenerator=wd_sparql_query(sparql_query)
      mailmessage=f'query: {sparql_query}\nItems processed: {items_processed}'
      #mailmessage='one-without-description: Q19389637'
    if (pigenerator==None) or (forcehourly):
       print('Force hourly script...')
       pigenerator=generator_last_hour()
       mailmessage='hourly'

    if (commit):
      print('Commit')
    else:
      print('No commit modus!')
    totalreads=0
    for wd in pigenerator:
      totalreads+=1
      if prelog: log_premature(wd.title())            
      if debug: print('Found: %s' % wd.title())
      thisfound,thisone = action_one_item(run_lng,repo,wd)
      items_processed += thisone
      #if (items_processed>12): break
      #if ((items_processed>maxwrites) and (maxwrites>0)): break
      
      
    print(f'Klaar: {items_processed}')
    if (items_processed>10): sendmail('Run completed!',totalreads,items_processed);  #often runs for two weeks ... mail me to notify

def wd_all_items(direction):
  startrange= 80999999 
  stoprange = 80000000 

  startrange= 79788588 
  stoprange = 79000000 
  startrange= 78823351 
  stoprange = 78000000 
  startrange= 77196790
  stoprange = 77000000 

  #startrange= 50000100 
  #stoprange = 50000000 
  
  repo=pywikibot.Site('wikidata','wikidata').data_repository()
  for itemno in range(startrange,stoprange,direction):
   try: 
    wd=pywikibot.ItemPage(repo,'Q%d' % itemno)
    if not wd.isRedirectPage():
     if wd.exists():
      wd.get(get_redirect=True)
      yield wd
    else:
      pass
    itemno -= 1
   except:
     pass

print('Ik loop')
forcehourly=False
try:    
  if (len(sys.argv)>1):
    if (sys.argv[1].lower()=='hourly'):
      forcehourly=True
    elif (sys.argv[1].lower()=='range'):
      pass        
    elif (sys.argv[1].lower()=='yyy'):
      pass        
    elif (sys.argv[1].lower()=='zzz'):
      pass        
    else:
      print(sys.argv[1].lower())
  else:
    print(len(sys.argv))
  if(debugedo):
    print("debug mode: start")
    testrun()
  else : 
    main()
finally:syndicat intercommunal in Croisilles
  pywikibot.stopme()
Ik loop
-f
main
Commit
Sleeping for 5.0 seconds, 2020-06-24 13:45:24
Sleeping for 5.0 seconds, 2020-06-24 13:45:29
Sleeping for 5.0 seconds, 2020-06-24 13:45:34
Sleeping for 5.0 seconds, 2020-06-24 13:45:39
Sleeping for 5.0 seconds, 2020-06-24 13:45:44
Sleeping for 5.0 seconds, 2020-06-24 13:45:49
Sleeping for 5.0 seconds, 2020-06-24 13:45:55
Sleeping for 5.0 seconds, 2020-06-24 13:46:00
Sleeping for 5.0 seconds, 2020-06-24 13:46:05
Sleeping for 5.0 seconds, 2020-06-24 13:46:10
Sleeping for 5.0 seconds, 2020-06-24 13:46:15
Sleeping for 5.0 seconds, 2020-06-24 13:46:20
Sleeping for 5.0 seconds, 2020-06-24 13:46:25
Sleeping for 5.0 seconds, 2020-06-24 13:46:30
Sleeping for 5.0 seconds, 2020-06-24 13:46:35
Sleeping for 5.0 seconds, 2020-06-24 13:46:41
Sleeping for 5.0 seconds, 2020-06-24 13:46:46
Sleeping for 5.0 seconds, 2020-06-24 13:46:51
Sleeping for 5.0 seconds, 2020-06-24 13:46:56
Sleeping for 5.0 seconds, 2020-06-24 13:47:01
Sleeping for 5.0 seconds, 2020-06-24 13:47:06
Sleeping for 5.0 seconds, 2020-06-24 13:47:11
Sleeping for 5.0 seconds, 2020-06-24 13:47:16
Sleeping for 5.0 seconds, 2020-06-24 13:47:21
Sleeping for 5.0 seconds, 2020-06-24 13:47:27
Sleeping for 5.0 seconds, 2020-06-24 13:47:32
Sleeping for 5.0 seconds, 2020-06-24 13:47:37
Sleeping for 5.0 seconds, 2020-06-24 13:47:42
Sleeping for 5.0 seconds, 2020-06-24 13:47:47
Sleeping for 5.0 seconds, 2020-06-24 13:47:52
Sleeping for 5.0 seconds, 2020-06-24 13:47:57
Sleeping for 5.0 seconds, 2020-06-24 13:48:02
Sleeping for 5.0 seconds, 2020-06-24 13:48:08
Sleeping for 5.0 seconds, 2020-06-24 13:48:13
Sleeping for 5.0 seconds, 2020-06-24 13:48:18
Sleeping for 5.0 seconds, 2020-06-24 13:48:23
Sleeping for 5.0 seconds, 2020-06-24 13:48:28
Sleeping for 5.0 seconds, 2020-06-24 13:48:33
Sleeping for 5.0 seconds, 2020-06-24 13:48:38
Sleeping for 5.0 seconds, 2020-06-24 13:48:43
Sleeping for 5.0 seconds, 2020-06-24 13:48:48
Sleeping for 5.0 seconds, 2020-06-24 13:48:54
Sleeping for 5.0 seconds, 2020-06-24 13:48:59
Sleeping for 5.0 seconds, 2020-06-24 13:49:04
Sleeping for 5.0 seconds, 2020-06-24 13:49:09
Sleeping for 5.0 seconds, 2020-06-24 13:49:14
Sleeping for 5.0 seconds, 2020-06-24 13:49:19
Sleeping for 5.0 seconds, 2020-06-24 13:49:24
Sleeping for 5.0 seconds, 2020-06-24 13:49:29
Sleeping for 5.0 seconds, 2020-06-24 13:49:34
Sleeping for 5.0 seconds, 2020-06-24 13:49:40
Sleeping for 5.0 seconds, 2020-06-24 13:49:45
Sleeping for 5.0 seconds, 2020-06-24 13:49:50
Sleeping for 5.0 seconds, 2020-06-24 13:49:55
Sleeping for 5.0 seconds, 2020-06-24 13:50:00
Sleeping for 5.0 seconds, 2020-06-24 13:50:05
Sleeping for 5.0 seconds, 2020-06-24 13:50:10
Sleeping for 5.0 seconds, 2020-06-24 13:50:15
Sleeping for 5.0 seconds, 2020-06-24 13:50:20
Sleeping for 5.0 seconds, 2020-06-24 13:50:26
Sleeping for 5.0 seconds, 2020-06-24 13:50:31
Sleeping for 5.0 seconds, 2020-06-24 13:50:36
Sleeping for 5.0 seconds, 2020-06-24 13:50:41
Sleeping for 5.0 seconds, 2020-06-24 13:50:46
Sleeping for 5.0 seconds, 2020-06-24 13:50:51
Sleeping for 5.0 seconds, 2020-06-24 13:50:56
Sleeping for 5.0 seconds, 2020-06-24 13:51:01
        -5 Q94692806
Sleeping for 9.1 seconds, 2020-06-24 13:51:09
        -7 Q94582472
Sleeping for 8.8 seconds, 2020-06-24 13:51:19
       -10 Q94580727
Sleeping for 8.6 seconds, 2020-06-24 13:51:29
       -18 Q94639214
Sleeping for 8.0 seconds, 2020-06-24 13:51:40
       -30 Q94611101
Sleeping for 7.5 seconds, 2020-06-24 13:51:51
       -32 Q94610340
Sleeping for 9.0 seconds, 2020-06-24 13:51:59
       -42 Q94611001
Sleeping for 7.6 seconds, 2020-06-24 13:52:11
       -54 Q94610841
Sleeping for 7.4 seconds, 2020-06-24 13:52:21
       -62 Q94576672
Sleeping for 8.2 seconds, 2020-06-24 13:52:30
       -72 Q94610140
Sleeping for 7.8 seconds, 2020-06-24 13:52:40
       -75 Q94612178
Sleeping for 8.9 seconds, 2020-06-24 13:52:49
       -86 Q94575775
Sleeping for 7.4 seconds, 2020-06-24 13:53:01
       -90 Q94639083
Sleeping for 8.8 seconds, 2020-06-24 13:53:09
       -91 Q94576304
Sleeping for 9.2 seconds, 2020-06-24 13:53:19
       -94 Q94576026
Sleeping for 8.8 seconds, 2020-06-24 13:53:29
       -99 Q94693148
Sleeping for 8.3 seconds, 2020-06-24 13:53:40
      -100 Q94610400
Sleeping for 9.2 seconds, 2020-06-24 13:53:49
      -104 Q94612367
Sleeping for 8.6 seconds, 2020-06-24 13:54:00
      -107 Q94576369
Sleeping for 8.7 seconds, 2020-06-24 13:54:09
      -108 Q94610237
Sleeping for 9.0 seconds, 2020-06-24 13:54:19
      -117 Q94611030
Sleeping for 7.1 seconds, 2020-06-24 13:54:31
      -121 Q94577200
Sleeping for 8.6 seconds, 2020-06-24 13:54:40
      -122 Q94581652
Sleeping for 9.0 seconds, 2020-06-24 13:54:49
      -123 Q94575870
Sleeping for 8.8 seconds, 2020-06-24 13:54:59
      -131 Q94575125
Sleeping for 8.0 seconds, 2020-06-24 13:55:10
      -135 Q94639454
Sleeping for 8.3 seconds, 2020-06-24 13:55:20
      -137 Q94693282
Sleeping for 8.6 seconds, 2020-06-24 13:55:30
      -145 Q94612305
Sleeping for 7.3 seconds, 2020-06-24 13:55:41
      -149 Q94576811
Sleeping for 8.4 seconds, 2020-06-24 13:55:50
      -154 Q94573958
Sleeping for 8.3 seconds, 2020-06-24 13:56:00
      -156 Q94610273
Sleeping for 8.9 seconds, 2020-06-24 13:56:09
      -164 Q94576364
Sleeping for 8.3 seconds, 2020-06-24 13:56:20
      -166 Q94610066
Sleeping for 9.1 seconds, 2020-06-24 13:56:29
      -194 Q94610007
Sleeping for 4.8 seconds, 2020-06-24 13:56:44
      -213 Q94639158
Sleeping for 5.6 seconds, 2020-06-24 13:56:53
      -214 Q94610035
Sleeping for 8.9 seconds, 2020-06-24 13:56:59
      -223 Q94576800
Sleeping for 7.7 seconds, 2020-06-24 13:57:11
      -225 Q94692820
Sleeping for 8.7 seconds, 2020-06-24 13:57:20
      -228 Q94610797
Sleeping for 8.8 seconds, 2020-06-24 13:57:30
      -234 Q94693385
Sleeping for 4.1 seconds, 2020-06-24 13:57:44
      -241 Q94577149
Sleeping for 8.2 seconds, 2020-06-24 13:57:50
      -242 Q94693021
Sleeping for 9.0 seconds, 2020-06-24 13:57:59
      -249 Q94611097
Sleeping for 8.1 seconds, 2020-06-24 13:58:10
      -253 Q94610017
Sleeping for 8.5 seconds, 2020-06-24 13:58:20
      -257 Q94610208
Sleeping for 8.7 seconds, 2020-06-24 13:58:30
      -260 Q94610634
Sleeping for 4.3 seconds, 2020-06-24 13:58:34
      -262 Q94610980
Sleeping for 8.8 seconds, 2020-06-24 13:58:40
      -283 Q94574336
Sleeping for 6.3 seconds, 2020-06-24 13:58:52
      -287 Q94610282
Sleeping for 8.3 seconds, 2020-06-24 13:59:00
Sleeping for 5.0 seconds, 2020-06-24 13:59:09
Sleeping for 4.9 seconds, 2020-06-24 13:59:14
Sleeping for 5.0 seconds, 2020-06-24 13:59:19
Sleeping for 4.8 seconds, 2020-06-24 13:59:24
Sleeping for 5.0 seconds, 2020-06-24 13:59:29
Sleeping for 4.9 seconds, 2020-06-24 13:59:34
Sleeping for 5.0 seconds, 2020-06-24 13:59:39
Sleeping for 4.8 seconds, 2020-06-24 13:59:44
Sleeping for 5.0 seconds, 2020-06-24 13:59:49
Sleeping for 4.9 seconds, 2020-06-24 13:59:54
Sleeping for 5.0 seconds, 2020-06-24 13:59:59
Sleeping for 4.9 seconds, 2020-06-24 14:00:04
Sleeping for 5.0 seconds, 2020-06-24 14:00:09
Sleeping for 4.9 seconds, 2020-06-24 14:00:14
Sleeping for 5.0 seconds, 2020-06-24 14:00:19
Sleeping for 4.9 seconds, 2020-06-24 14:00:24
Sleeping for 5.0 seconds, 2020-06-24 14:00:29
Sleeping for 4.9 seconds, 2020-06-24 14:00:34
Sleeping for 5.0 seconds, 2020-06-24 14:00:39
Sleeping for 4.8 seconds, 2020-06-24 14:00:44
Sleeping for 5.0 seconds, 2020-06-24 14:00:49
Sleeping for 4.9 seconds, 2020-06-24 14:00:54
Sleeping for 5.0 seconds, 2020-06-24 14:00:59
Sleeping for 4.9 seconds, 2020-06-24 14:01:04
Sleeping for 5.0 seconds, 2020-06-24 14:01:09
Sleeping for 4.9 seconds, 2020-06-24 14:01:14
In [2]:
 
In [ ]: