User:Edoderoobot/Set-nl-description

From Wikidata
Jump to navigation Jump to search
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
#
# (C) Edoderoo/Edoderoobot (meta.wikimedia.org), 2015–2017
# Distributed under the terms of the CC-BY-SA 3.0 licence.
#

import pywikibot
#from pywikibot import pagegenerators
from pywikibot import pagegenerators as pg
#import pywikibot.data.wikidataquery as wdquery
from pywikibot.data import api
import codecs
import sys
import datetime
from datetime import datetime, date, time

#import nl-desc-itsa.py

#demoniem = P1549
geborenCLAIM =     u'P569'
gestorvenCLAIM=    u'P570'
is_eenCLAIM=       u'P31'
genderCLAIM =      u'P21'
female_genderPROP =u'Q6581072'
male_genderPROP =  u'Q6581097'
gelegen_inCLAIM=   u'P131'
beroepCLAIM=       u'P106'
items2do = 0
commit=False    #no changes online, only to the logfiles
commit=True     #write changes to the database


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
                      'Q532 ',   #dorp/village
                      'Q3863',   #planetoide
                      'Q8502',   #berg
                      'Q9842',   #basisschool
                      'Q16521',  #taxon
                      'Q134556', #music single
                      'Q101352', #last name
                      'Q202444', #first name
                      'Q207628', #compositie
                      'Q215380', #musicband
                      'Q222910', #music album
                      'Q253019', #ortsteil
                      'Q486972', #nederzetting
                      'Q482994', #music album
                      'Q1348589', #maankrater
                      'Q5633421', #scientific magazine
                      'Q13442814', #scientific article
                      'Q20741022', #model digital camera
                      'Q23925393', #douar, Marokkaans bestuurlijkg gebied
                      ]
run_lng = u'nl'
txt2skip = u'|skip!|'
output2screen = False
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= False

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=[
            'Q188509',
            'Q3914', #school
            'Q355304', #watergang
            'Q23012917', 'Q2225692','Q4174776','Q13100073','Q23827464','Q3558970','Q15630849','Q21672098', #dorpen
            'Q54050',#heuvel
            'Q24764', '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',
            'Q9842','Q23925393','','','','','','','','','','','','','','','',
           ]              
               
debugedo=True   #use one item, just to test
debugedo=False  #use wd-query, process a lot


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):    
  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,'xxx')

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_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)
  
"""
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_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','')
  

  
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']) or \
                     (WDIperson.descriptions[lng].find('n/a') > 0) or \
                     (WDIperson.descriptions[lng].find('sporter') > 0) or \
                     (WDIperson.descriptions[lng].find('(-)')>0) 

    """
    if not(update_desc):      
       if not(lng in WDIperson.labels):
         return(WDIperson.descriptions[lng],'')
       else :
         return('',txt2skip) #there is already a description
    """                     
        
    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  
    print('%s' % my_description)
    return(my_description, missing)

def its_something_in_an_entity(lng,repo,wdi,something):
  prnEntity = ''
  prnCountry = ''
  if (gelegen_inCLAIM in wdi.claims):
    LNKentity = wdi.claims.get(gelegen_inCLAIM)[0].getTarget()
    try:
      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 'P17' in wdi.claims:  
      LNKcountry = wdi.claims.get('P17')[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''
          missing = WDIcountry.title()
      except :
        missing = wdi.title()
      
      if (prnCountry!=''):
        return('%s %s, %s' % (something, prnEntity, prnCountry),'')  
      else:
        return('%s %s' % (something, prnEntity),'')  
  else:
    return('',txt2skip)  
    
def its_something_in_a_country(lng,repo,wdi,something):
    prnCountry = u'unknown'
    if (lng in wdi.descriptions):
      if (wdi.descriptions[lng] != ''):
        return(wdi.descriptions[lng],txt2skip)
    missing = u''
    if 'P17' in wdi.claims:  
      LNKcountry = wdi.claims.get('P17')[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 = u''
  missing = ''
  my_desc = u'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_desc = u'Kanton in '+WDIcommunity.labels[lng]+u', Frankrijk'
    #get P131  'Kanton in P131, Frankrijk'
  else:
    missing = txt2skip  
  return(my_desc,missing)
        
def its_a_mountain(lng,repo,wdi):
    return(its_something_in_a_country(lng,repo,wdi,'berg in'))      
      
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_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)
    
    if (lng in WDIseries.labels):
      return('aflevering van '+WDIseries.labels[lng],'')
    else :
      return('aflevering van '+WDIseries.title(), txt2skip)
  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')  
  
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'))  

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')
    
  
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'))

def its_a_tvprogram(lng,repo,wditem):
  if lng in wditem.descriptions:
    return(wditem.descriptions[lng],txt2skip)
  if ('P17' in wditem.claims):
    return(its_something_in_a_country(lng,repo,wditem,'televisieprogramma uit'))
  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_galaxy(lng,repo,wditem):
  return its_a_generalthing(lng,repo,wditem,'sterrenstelsel','sterrenstelsel in ','P59')
  if ('P59' in wditem.claims):
    LNKgalaxy = wditem.claims.get('P59')[0].getTarget()
    WDIgalaxy = pywikibot.ItemPage(repo,LNKgalaxy.title())
    WDIgalaxy.get(get_redirect=True)
    if lng in WDIgalaxy.labels:
        return('sterrenstelsel in '+WDIgalaxy.labels[lng],'') 
    
  return('sterrenstelsel','')
  
def its_a_book(lng,repo,wditem):
  authorname = u''
  if (lng in wditem.descriptions):
    if (wditem.descriptions[lng] != u'boek'):
      return('',txt2skip)
  return its_a_generalthing(lng,repo,wditem,'boek','boek van ','P50')

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

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')
      
def its_a_generalthing(lng,repo,wditem,shortstr,longdescrstr,myclaim):
  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]
        else:
          for trylng in lng_canbeused:
            if (claimstr=='') and (trylng in WDIitem.labels):
               claimstr = WDIitem.labels[trylng]          
  except:
    pass
    
  if claimstr=='':
    #print('\n%s%s%s' % (wditem.title(), 'short: ',shortstr))
    return(shortstr,'')
  else:
    returnstr = ('%s%s' % (longdescrstr,claimstr))
    #print('\n%s%s%s' % (wditem.title(),' long:',returnstr))
    return(returnstr,'')
     
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):  
      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 ('P17' in oneitem.claims):
        LNKcountry=oneitem.claims.get('P17')[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 }})
      else:  
        print('%s-[%s]-[%s]-<%s>' %(oneitem.title(),nll,nld,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)
        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_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)
      if (lng in LNKdirector.labels):
        return('film van %s' % LNKdirector.labels[lng],'')
      elif ('en' in LNKdirector.labels):
        return('film van %s' % LNKdirector.labels['en'],'')
  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)
      if (lng in WDitemtambon.labels):
        newdescription='tambon in %s, Thailand' % WDitemtambon.labels[lng]
      elif ('en' in WDitemtambon.labels):
        newdescription='tambon in %s, Thailand' % WDitemtambon.labels['en']
      elif ('de' in WDitemtambon.labels):
        newdescription='tambon in %s, Thailand' % WDitemtambon.labels['de']
      else:
        return('',txt2skip)
  return(newdescription,'')      
  
def action_one_item(lng, repo, wditem):
    global output2screen
    global items2do
    
    items_found=0
    missing = u''
    my_description=u''
    orig_desc = get_description(lng,wditem).lower()
    en_description = u''
    en_description = get_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))
                                    
    if (is_eenCLAIM in wditem.claims):
      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','kunstschilder']):
        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
        my_description,missing=its_a_galaxy(lng,repo,wditem)      
        placefound='galaxy'
      elif type_of_item=='Q215380': #muziekband
        if (orig_desc in ['','']):
          my_description,missing = its_a_band(lng,repo,wditem)
        placefound='band'
      elif type_of_item=='Q39367': #hondenras
        if (orig_desc in ['','']):
          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 ['','']):  
          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')
        elif (not commit):
          print('nederzetting %d-%d, [%s]' % (l1,l2,orig_desc))
        placefound='nederzetting'
      elif type_of_item=='Q14752149':  #amateur football club
        if (orig_desc in ['','']):
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'amateurvoetbalclub uit')
          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')
          placefound='organisatie'
      elif type_of_item=='Q728937': #railway line
        if (orig_desc in ['','']):      
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'spoorlijn in')
          placefound='railwayline'
      elif type_of_item=='Q7278': #political party
        if (orig_desc in ['','']):      
          my_description,missing=its_something_in_a_country(lng,repo,wditem,'politieke partij uit')
          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 ')
          if (my_description in ['','']):
            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')
          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')
        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
        pass
        placefound='gebeurtenis'
      elif type_of_item=='Q1539532':
        pass
        placefound='sportseizoen'

      elif type_of_item=='Q3231690': #automodel van P176
        if (orig_desc in ['','']):      
          my_description,missing = its_a_carmodel(lng,repo,wditem)
          placefound='automodel'
      elif type_of_item=='Q3192808': #commune in Madagascar
        if (orig_desc in ['','']):      
          my_description='commune in Madagascar'
          placefound='madagascar'
      elif type_of_item=='Q1092563': #periodiek in het genre P136
        if (orig_desc in ['periodiek','']):      
          my_description,missing = its_a_generalthing(lng,repo,wditem,'periodiek','periodiek in het genre ','P136')
          placefound='periodiek'
      elif type_of_item=='Q18536594': #sportevenement op de Olympische Spelen
        if (orig_desc in ['','']):      
          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 ['','']):      
          pass
          placefound='computerspel'
      elif type_of_item=='Q659103':  #gemeente in P131, Roemenië
        if (orig_desc in ['','']):      
          pass
          placefound='Roemenie'
      elif type_of_item=='Q15081032': #historisch motorfietsmerk
        if (orig_desc in ['','']):       
          pass
          placefound='motorfiets'
      elif type_of_item=='Q178561': #veldslag in #P17
        if (orig_desc in ['','']):      
          pass
          placefound='veldslag'
      elif type_of_item=='Q618779': #onderscheiding
        if (orig_desc in ['','']):      
          pass
          placefound='awardy'
      elif type_of_item=='Q106259': #polder in P131, P17
        if (orig_desc in ['','']):      
          pass
          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','']):      
          my_description = u'gemeente in Brazilië'
          placefound='Brazil'
      elif type_of_item=='Q2635894':  #hoorspel uit de serie P179/uit P495
        if (orig_desc in ['','']):      
          pass
          placefound='hoorspel'
      elif type_of_item=='Q523':  #ster uit het sterrenbeeld P59
        if (orig_desc in ['','']):      
          pass
          placefound='ster'
      elif type_of_item=='Q197': #vliegtuig van P176
        if (orig_desc in ['','']):      
          pass
          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 ['','']):      
          pass
          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 ['','']):      
          pass
          placefound='wijk'
      elif type_of_item=='Q14659': #heraldisch wapen uit P17
        if (orig_desc in ['heraldisch wapen','']):      
          pass
          placefound='heraldiek'
      elif type_of_item=='Q2831984': #stripalbum uit de serie P179
        if (orig_desc in ['','']):      
          pass
          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','']):      
          pass
          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','Landkreis','']):      
          pass
          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=='Q2912397': #eendagswielerwedstrijd in P17
        if (orig_desc in ['eendaagse wielerwedstrijd','']):      
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'eendaagse wielerwedstrijd in ')
          placefound='1dagswielerkoers'
      elif type_of_item=='Q355304':
        if (orig_desc in ['','watergang']):      
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'watergang in ')
          placefound='watergang'
      elif type_of_item=='Q34763':
        if (orig_desc in ['schiereiland','']):      
          my_description,missing = its_something_in_a_country(lng,repo,wditem,u'schiereiland in ')
          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 ')
          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 ')
          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')
          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 ')
          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 ')
          placefound='parochie'
      elif type_of_item=='Q9842':
        if (orig_desc in ['basisschool','']):      
          my_description,missing = its_something_in_a_country(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 ')
          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': #pokemon
        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':
        if (orig_desc in ['tijdschrift','']):      
          my_description = u'wetenschappelijk tijdschrift'  #van P123
          missing = ''
          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=='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')
          placefound='x'
      elif type_of_item=='Q985488':
        if (orig_desc in ['bewonersgemeenschap','']):      
          my_description,missing = its_something_in_a_country(lng,repo,wditem,'bewonersgemeenschap in')
          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')
          placefound='meer'
      elif type_of_item=='Q2996394':
        if (orig_desc in ['','']):      
          my_description = 'biologisch proces'
          placefound='biologisch proces'
      elif type_of_item=='Q14860489':
        if (orig_desc in ['','']):      
          my_description = 'moleculaire functie'
          placefound='mol.func'
      elif type_of_item=='Q5058355':
        if (orig_desc in ['','']):      
          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':
        if (orig_desc in ['lied','']):      
          my_description,missing = its_a_generalthing(lng,repo,wditem,'lied','lied van','P175')
          placefound='lied'
      elif type_of_item=='Q21278897':
        if (orig_desc in ['','']):      
          my_description = 'Wiktionary-doorverwijzing'
          placefound='wikt.redirect'
      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.sitelinks):  #use link-name of same lng as label 
                newlabel=wditem.sitelinks[lng+u'wiki']
                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 commit:  
             wditem.editEntity(data,summary=u'nl-description, [[User:Edoderoobot/Set-nl-description|python code]], logfile on https://goo .gl/BezTim')
             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

      else:
        pass
        #print('Hiero: [%s]-[%s]-[b:%s]' %(my_description,missing, not (lng in wditem.labels)))      
    return items_found

    
    
    
    
    

def testrun():        
 global output2screen
 output2screen = True
 site = pywikibot.Site()
 repo = site.data_repository()


 item2get = 'Q2251998' #Sadet Karabulut
 item2get = 'Q6184'
 item2get = 'Q565062' #Anne Bous, birthdate & date of death : only year is specified
 item2get = 'Q23433337' #Chris Niehuis
 item2get='Q20431412123123' #redirected page
 item2get = 'Q163532'
 item2get = 'Q13671768'
 item2get = 'Q14797861' 
 
 x = pywikibot.ItemPage(repo, item2get)
 x.get(get_redirect=True) 
 if x.exists():
   action_one_item('nl',repo,x)
   #print('[%s][%s]' % (x.descriptions['nl'],''))
 else:
   print('no action!') 
 
 """
 #claim = x.claims.get('P2046')# [0].getTarget()
 #claim = x.claims#.get('P1082')# [0].getTarget()
 
 for findsources in x.claims['P2044'][0].sources:
   for onesource in findsources:
      for xxx in findsources[onesource]:
         print ("%s - %s" % (onesource, dir(xxx)))
   print("================================")
 
 for ref in x.getReferences():  #alt-shift-J / what-links-here
  print(ref)
  print("================================")
 """

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:
    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 wd_all_items():
  #stoprange= 
  startrange= 33590000 #25000
  #stoprange = 33340000
  
  #startrange= 33340000
  #stoprange = 33090000
  
  #startrange= 33090000
  #stoprange = 32840000
  
  #startrange= 32840000
  #stoprange = 32590000
  
  #startrange= 32590000
  #stoprange = 32340000
  
  #startrange= 32340000
  #stoprange = 32090000
  
  #startrange= 32090000
  #stoprange = 31840000
  
  #startrange= 31840000
  #stoprange = 31590000
  
  #startrange= 31590000
  #stoprange = 31340000
  
  #startrange= 31340000
  stoprange = 31100000
  
  repo=pywikibot.Site('wikidata','wikidata').data_repository()
  for itemno in range(startrange,stoprange,-1):
   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

  
def sparql_nodescription(sparql):
  return 'select distinct ?item where {{%s}filter (!bound(?itemDescription))}' % sparql  
 
def main(debug=False):
    print ("main")
    
    """
    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=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=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:Q3863}'    

    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:Q486972 . ?item wdt:P17 wd:%s}'  #nederzetting per land
    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:Q253019}'
    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:Q1077097 }'
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q11424}' #film 
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q15416}' #televisieprogramma
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q985488}' #bewonersgemeenschap in ?land
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q7366}' #lied
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q4830453}' #onderneming
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q23397}' #meer 
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q1539532}' #sportseizoen -> pass
    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:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:}' #
    sparql_query='SELECT ?item WHERE {  ?item wdt:P31 wd:Q43229}' #organisatie
    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:Q134556}' #single
    
    site=pywikibot.Site('wikidata','wikidata')
    repo=site.data_repository()
    
    items_processed=0

    lng = run_lng
    if debug: print("main-1")
    
    if (True):
     pass
     #pigenerator = wd_from_file('')
     #pigenerator = wd_all_countries(sparql_query)
     #pigenerator = wd_all_without_description()
     #pigenerator = wd_all_without_description()
     #pigenerator = wd_all_countries(sparql_query)
     pigenerator=wd_sparql_query(sparql_query)
     #pigenerator = wd_all_items()
       
     #pigenerator = wd_user_edits('Andre Engels',site,10000)
     #pigenerator = wd_user_edits('GerardM',site,10000)
     #pigenerator = wd_user_edits('Sjoerddebruin',site,10000)
     #pigenerator = wd_user_edits('Mbch331',site,10000)
      #pigenerator = wd_user_edits('Mushroom',site,10000)
     #pigenerator = wd_user_edits('Ary29' ,site,10000)
     #pigenerator = wd_user_edits('Queryzo', site, 10000)
     #pigenerator = wd_user_edits('Andrei Stroe',site,10000)
     #pigenerator = wd_user_edits('Polyfoam',site,10000)
     #pigenerator = wd_user_edits('Jonathan Groß',site,10000)
     #pigenerator = wd_user_edits('YanikB',site,10000)
     #pigenerator = wd_user_edits('Olaf Studt',site,10000)
     #pigenerator = wd_user_edits('Floscher',site,10000)
     #pigenerator = wd_user_edits('WikiDataMovieDB',site,10000)
     #pigenerator = wd_user_edits('Chaoborus',site,10000)
     #pigenerator = wd_user_edits('Edoderoo',site,10000)
     #pigenerator = wd_user_edits('NoclaimsBot',site, 50000)
     #pigenerator = wd_all_simple_P131()
     #pigenerator = wd_user_edits('Edoderoo',site,51111)
     #pigenerator = wd_all_items()
     #pigenerator = wd_all_countries(sparql_query)
   
     
    #pigenerator=pigenerator = wd_all_items()
    
    if (commit):
      print('Start')
    else:
      print('No commit modus!')    
    for wd in pigenerator:
      if prelog: log_premature(wd.title())            
      #print('Found: %s' % wd.title())
      thisone = action_one_item(run_lng,repo,wd)
      items_processed += thisone
      if (thisone==0) and (skiplog): log_skipped(wd.title())
      #if (items_processed>11): break
      
      
    print('Klaar: %d' % items_processed)


    
try:    
  if(debugedo):
    print("debug mode: start")
    testrun()
  else : 
    main()
finally:
  pywikibot.stopme()