]> Nutra Git (v1) - gamesguru/getmyancestors.git/commitdiff
add link parents sealing to childs
authorlinek <benoitfontaine.ba@gmail.com>
Sun, 16 Jul 2017 20:42:11 +0000 (22:42 +0200)
committerlinek <benoitfontaine.ba@gmail.com>
Sun, 16 Jul 2017 20:42:11 +0000 (22:42 +0200)
getmyancestors.py
mergemyancestors.py

index 96b2906b8a8512b740f6ff0c77b8001655c29483..6c90d9770ba9027702f59a128c2c4147461bcf2c 100755 (executable)
@@ -336,12 +336,16 @@ class Name:
 class Ordinance():
 
     def __init__(self, data=None):
-        self.date = self.temple_code = self.status = None
+        self.date = self.temple_code = self.status = self.famc = None
         if data:
             if 'date' in data:
                 self.date = data['date']['formal']
             if 'templeCode' in data:
                 self.temple_code = data['templeCode']
+            if 'father' in data and 'mother' in data:
+                famc = (data['father']['resourceId'], data['mother']['resourceId'])
+                if famc in tree.fam:
+                    self.famc = tree.fam[famc]
             if data['status'] == u'http://familysearch.org/v1/Completed':
                 self.status = 'COMPLETED'
             if data['status'] == u'http://familysearch.org/v1/Cancelled':
@@ -356,6 +360,8 @@ class Ordinance():
             file.write('2 TEMP ' + self.temple_code + '\n')
         if self.status:
             file.write('2 STAT ' + self.status + '\n')
+        if self.famc:
+            file.write('2 FAMC @F' + str(self.famc.num) + '@\n')
 
 
 # GEDCOM individual class
@@ -406,16 +412,12 @@ class Indi:
                             if y['type'] == u'http://gedcomx.org/MarriedName':
                                 self.married.add(Name(y))
                 if 'gender' in x:
-                    if x['gender']['type'] == "http://gedcomx.org/Male":
-                        self.gender = "M"
-                    elif x['gender']['type'] == "http://gedcomx.org/Female":
-                        self.gender = "F"
-                else:
-                    self.gender = None
-                notes = fs.get_url(x['links']['notes']['href'])
-                if notes:
-                    for n in notes['persons'][0]['notes']:
-                        self.notes.add(Note('===' + n['subject'] + '===\n' + n['text'] + '\n'))
+                    if x['gender']['type'] == 'http://gedcomx.org/Male':
+                        self.gender = 'M'
+                    elif x['gender']['type'] == 'http://gedcomx.org/Female':
+                        self.gender = 'F'
+                    elif x['gender']['type'] == 'http://gedcomx.org/Unknown':
+                        self.gender = 'U'
                 for y in x['facts']:
                     if y['type'] == u'http://gedcomx.org/Birth':
                         self.birtdate = y['date']['original'] if 'date' in y and 'original' in y['date'] else None
@@ -440,6 +442,10 @@ class Indi:
                             self.sources.add((Source.add_source(json), y['attribution']['changeMessage']))
                         else:
                             self.sources.add((Source(json),))
+                notes = fs.get_url(x['links']['notes']['href'])
+                if notes:
+                    for n in notes['persons'][0]['notes']:
+                        self.notes.add(Note('===' + n['subject'] + '===\n' + n['text'] + '\n'))
         self.parents = None
         self.children = None
         self.spouses = None
@@ -454,21 +460,6 @@ class Indi:
         if famc not in self.famc_fid:
             self.famc_fid.add(famc)
 
-    # retrieve and add LDS ordinances
-    def add_ordinances(self):
-        url = 'https://familysearch.org/platform/tree/persons/' + self.fid + '/ordinances.json'
-        data = fs.get_url(url)['persons'][0]['ordinances']
-        if data:
-            for o in data:
-                if o['type'] == u'http://lds.org/Baptism':
-                    self.baptism = Ordinance(o)
-                if o['type'] == u'http://lds.org/Confirmation':
-                    self.confirmation = Ordinance(o)
-                if o['type'] == u'http://lds.org/Endowment':
-                    self.endowment = Ordinance(o)
-                if o['type'] == u'http://lds.org/SealingChildToParents':
-                    self.sealing_child = Ordinance(o)
-
     # retrieve parents
     def get_parents(self, fs):
         if not self.parents:
@@ -502,6 +493,25 @@ class Indi:
                 self.spouses = [(x['person1']['resourceId'], x['person2']['resourceId'], x['id']) for x in data['relationships']]
         return self.spouses
 
+    # retrieve and add LDS ordinances
+    def get_ordinances(self):
+        res = []
+        url = 'https://familysearch.org/platform/tree/persons/' + self.fid + '/ordinances.json'
+        data = fs.get_url(url)['persons'][0]['ordinances']
+        if data:
+            for o in data:
+                if o['type'] == u'http://lds.org/Baptism':
+                    self.baptism = Ordinance(o)
+                if o['type'] == u'http://lds.org/Confirmation':
+                    self.confirmation = Ordinance(o)
+                if o['type'] == u'http://lds.org/Endowment':
+                    self.endowment = Ordinance(o)
+                if o['type'] == u'http://lds.org/SealingChildToParents':
+                    self.sealing_child = Ordinance(o)
+                if o['type'] == u'http://lds.org/SealingToSpouse':
+                    res.append(o)
+        return res
+
     # print individual information in GEDCOM format
     def print(self, file=sys.stdout):
         file.write('0 @I' + str(self.num) + '@ INDI\n')
@@ -629,17 +639,6 @@ class Fam:
                 for n in notes['relationships'][0]['notes']:
                     self.notes.add(Note('===' + n['subject'] + '===\n' + n['text'] + '\n'))
 
-    # retrieve and add LDS ordinances
-    def add_ordinance(self):
-        if self.husb_fid and self.wife_fid:
-            url = 'https://familysearch.org/platform/tree/persons/' + self.husb_fid + '/ordinances.json'
-            data = fs.get_url(url)['persons'][0]['ordinances']
-            if data:
-                for o in data:
-                    if o['type'] == 'http://lds.org/SealingToSpouse':
-                        if o['spouse']['resourceId'] == self.wife_fid:
-                            self.sealing_spouse = Ordinance(o)
-
     # print family information in GEDCOM format
     def print(self, file=sys.stdout):
         file.write('0 @F' + str(self.num) + '@ FAM\n')
@@ -662,6 +661,8 @@ class Fam:
                 file.write('2 DATE ' + o.date + '\n')
             if o.place:
                 file.write('2 PLAC ' + o.place + '\n')
+            if o.note:
+                file.write('2 NOTE @N' + str(o.note.num) + '@\n')
         if self.sealing_spouse:
             file.write('1 SLGS\n')
             self.sealing_spouse.print(file)
@@ -838,9 +839,12 @@ if __name__ == '__main__':
     # download LDS ordinances
     if args.c:
         for fid, indi in tree.indi.items():
-            indi.add_ordinances()
-        for fid, fam in tree.fam.items():
-            fam.add_ordinance()
+            ret = indi.get_ordinances()
+            for o in ret:
+                if (fid, o['spouse']['resourceId']) in tree.fam:
+                    tree.fam[(fid, o['spouse']['resourceId'])].sealing_spouse = Ordinance(o)
+                elif (o['spouse']['resourceId'], fid) in tree.fam:
+                    tree.fam[(o['spouse']['resourceId'], fid)].sealing_spouse = Ordinance(o)
 
     # compute number for family relationships and print GEDCOM file
     tree.reset_num()
index ad6e21981fd9c530486bb98a1933ae59b8ccb9c4..604ecb31113038b42ac7707eab3948f650d35ebc 100755 (executable)
@@ -58,7 +58,8 @@ class Gedcom:
                 self.__get_indi()
             elif self.tag == 'FAM':
                 self.num = int(self.pointer[2:len(self.pointer) - 1])
-                self.fam[self.num] = Fam(num=self.num)
+                if self.num not in self.fam:
+                    self.fam[self.num] = Fam(num=self.num)
                 self.__get_fam()
             elif self.tag == 'NOTE':
                 self.num = int(self.pointer[2:len(self.pointer) - 1])
@@ -308,6 +309,11 @@ class Gedcom:
                 ordinance.temple_code = self.data
             elif self.tag == 'STAT':
                 ordinance.status = self.data
+            elif self.tag == 'FAMC':
+                num = int(self.data[2:len(self.data) - 1])
+                if num not in self.fam:
+                    self.fam[num] = Fam(num=num)
+                ordinance.famc = self.fam[num]
         self.flag = True
         return ordinance
 
@@ -385,7 +391,8 @@ if __name__ == '__main__':
             tree.indi[fid].baptism = ged.indi[num].baptism
             tree.indi[fid].confirmation = ged.indi[num].confirmation
             tree.indi[fid].endowment = ged.indi[num].endowment
-            tree.indi[fid].sealing_child = ged.indi[num].sealing_child
+            if not (tree.indi[fid].sealing_child and tree.indi[fid].sealing_child.famc):
+                tree.indi[fid].sealing_child = ged.indi[num].sealing_child
 
         # add informations about families
         for num in ged.fam: