User:GeneaBot/Code/module person
< User:GeneaBot | Code
# -*- coding: utf-8 -*-
import pywikibot
from object_display import *
from object_source import *
from object_human import *
#======================================================
# Fonction PersonUpdate
#
def PersonUpdate(curRequest, Reference):
DisplayMessages.call("A", "PersonUpdate", 1, "curRequest=" + curRequest + ", Reference=" + repr(Reference) )
DisplayLog.AppendRequest( curRequest )
ident = ""
father = ""
mother = ""
spouse = ""
page = ""
Params = dict()
Family = []
defHumanClaims = Human.defaultClaims
# Process request PersonUpdate
curRequest = curRequest[:len(curRequest)-2] # suppress '}}' at the end request
listArgs = curRequest.split("|")
iArg = 1
while iArg < len(listArgs):
Statement = listArgs[iArg].split("=")
Property = Statement[0].strip()
try :
Value = Statement[1].strip()
except IndexError:
DisplayMessages.warning("A", "PersonUpdate", "parameter '" + Property + "' without argument")
iArg += 1
continue
DisplayMessages.debug("A", "PersonUpdate", 4, "Property= " + Property + ", Value= " + Value )
if not Value == "":
if Property == 'item':
ident = Value
elif Property == 'sex':
if Value == "F" or Value == "f" :
AddStatementTo(Params, 'P21', "Q6581072")
elif Value == "M" or Value == "m" :
AddStatementTo(Params, 'P21', "Q6581097")
elif Value == "H" or Value == "h" :
AddStatementTo(Params, 'P21', "Q6581097")
elif Property == 'occupation':
AddStatementTo(Params, 'P106', Value)
elif Property == 'given name':
AddStatementTo(Params, 'P735', Value)
elif Property == 'noble family':
AddStatementTo(Params, 'P53', Value)
elif Property == 'date of birth':
AddStatementTo(Params, 'P569', Value)
elif Property == 'date of death':
AddStatementTo(Params, 'P570', Value)
elif Property == 'place of birth':
AddStatementTo(Params, 'P19', Value)
elif Property == 'place of death':
AddStatementTo(Params, 'P20', Value)
elif Property == 'blason':
AddStatementTo(Params, 'P94', Value)
elif Property == 'father':
father = Value
elif Property == 'mother':
mother = Value
elif Property == 'spouse':
spouse = Value
elif Property == 'page':
page = Value
else:
DisplayMessages.warning("A", "PersonUpdate", "unknown parameter '" + Property + " = " + Value + "'")
iArg += 1
for Property in defHumanClaims:
if not Property in Params:
AddStatementTo(Params, Property, defHumanClaims[Property][0])
DisplayMessages.debug("A", "PersonUpdate", 4, "adding default : '" + Property + " = " + defHumanClaims[Property][0] + "'" )
#for Property in Human.optionalClaims:
# if not Property in Params:
# AddStatementTo(Params, Property, Human.optionalClaims[Property])
# DisplayMessages.debug("A", "PersonUpdate", 4, "adding default : '" + Property + " = " + Human.optionalClaims[Property] + "'" )
if page == "":
Ref = Reference
else:
RefPage = Source()
RefPage.AddReference('P304', page, True)
Ref = Reference + RefPage
DisplayMessages.debug("A", "PersonUpdate", 4, "parameter = " + str(Params) )
#
if not ident == "":
Person = Human.Get(ident, Params, Ref)
Family.append(Person)
DisplayMessages.debug("A", "PersonUpdate", 9, "Person = " + Person.display("short") )
if not father == "":
Father = Human.Get(father, defHumanClaims, Ref)
Person.SetParent('H', Father, Ref)
Family.append(Father)
DisplayMessages.debug("A", "PersonUpdate", 9, "Father = " + Father.display("short") )
if not mother == "":
Mother = Human.Get(mother, defHumanClaims, Ref)
Person.SetParent('F', Mother, Ref)
Family.append(Mother)
DisplayMessages.debug("A", "PersonUpdate", 9, "Mother = " + Mother.display("short") )
if not spouse == "":
Spouse = Human.Get(spouse, defHumanClaims, Ref)
Person.SetSpouse(Spouse, Ref)
Family.append(Spouse)
DisplayMessages.debug("A", "PersonUpdate", 9, "Spouse = " + Spouse.display("short") )
siblings = Person.GetSibling()
for key in siblings:
Family.append(siblings[key])
DisplayMessages.debug("A", "PersonUpdate", 9, "Siblings = " + siblings[key].display("short") )
return Family
def AddStatementTo(Param, Prop, Value):
DisplayMessages.call("A", "AddStatementTo", 4, "Param, Prop=" + Prop + ", Value=" + Value )
if not Prop in Param:
Param[Prop] = []
Param[Prop].append(Value)
def TestPersonUpdate(NumCase, curRequest, Reference, Format, Run):
print( "" )
print( "---------------------------" )
print( "test "+ str(NumCase) )
print( "Format=" + str(Format) + ", Run=" + str(Run) )
print( "PersonUpdate(curRequest=" + curRequest + ", Reference)" )
print( "" )
family = PersonUpdate(curRequest, Reference)
for member in family:
print( "" )
print( member.display(Format, Run) )
def mainTestPersonUpdate(*args):
param = CallParameter(*args)
NumCase = param.GetValue('case', 0)
DisplayMessages.SetFileName("")
ListDisplay = Display.split(':')
Format = ListDisplay[0]
if len(ListDisplay) >= 2:
Run = ListDisplay[1]
else:
Run = 'simu'
source = Source()
source.AddReference('P248', 'Q13419312', True)
source.AddReference('P854', 'http://fmg.ac/Projects/MedLands/GASCONY.htm', True)
if NumCase == 0 or NumCase == 1:
sourceSV = Source()
sourceSV.AddReference('P248', 'Q13419312', True)
sourceSV.AddReference('P854', 'http://fmg.ac/Projects/MedLands/SAVOY.htm', True)
request = '{{/PersonUpdate|item= Q312636 | given name=Q482154 |father= |mother=Q735117 }}'
TestPersonUpdate(1, request, sourceSV, Format, Run)
if NumCase == 0 or NumCase == 2:
sourceSV = Source()
sourceSV.AddReference('P248', 'Q13419312', True)
sourceSV.AddReference('P854', 'http://fmg.ac/Projects/MedLands/SAVOY.htm', True)
request = '{{/PersonUpdate|item= Q312636 | given name=Q482154 |father=Q451998 |mother=Q735117 |spouse=Q740325 }}'
TestPersonUpdate(2, request, sourceSV, Format, Run)
if NumCase == 0 or NumCase == 3:
request = '{{/PersonUpdate|item= Q2557324}}'
TestPersonUpdate(3, request, source, Format, Run)
if NumCase == 0 or NumCase == 4:
request = '{{/PersonUpdate|item= Q1286227 |date of birth=before 950}}'
TestPersonUpdate(4, request, source, Format, Run)
if __name__ == "__main__":
mainTestPersonUpdate()