]> Nutra Git (v2) - gamesguru/getmyancestors.git/commitdiff
added marriage facts
authorlinek <benoitfontaine.ba@gmail.com>
Sat, 15 Jul 2017 13:51:14 +0000 (15:51 +0200)
committerlinek <benoitfontaine.ba@gmail.com>
Sat, 15 Jul 2017 13:51:14 +0000 (15:51 +0200)
.gitignore [new file with mode: 0644]
getmyancestors.py
mergemyancestors.py

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e0003f5
--- /dev/null
@@ -0,0 +1,2 @@
+*.pyc
+*.ged
\ No newline at end of file
index 04a839f7b949626ffa04b5c7ddea1c624cec914f..e2a1b56cacff6bbcfc2886faa13ffa7554629cb7 100755 (executable)
@@ -284,10 +284,12 @@ class Source:
 class Fact:
 
     def __init__(self, data=None):
-        self.value = ''
-        self.date = self.place = self.note = None
+        self.value = self.type = self.date = self.place = self.note = None
         if data:
-            self.value = data['value']
+            if 'value' in data:
+                self.value = data['value']
+            if 'type' in data:
+                self.type = data['type']
             if 'date' in data:
                 self.date = data['date']['original']
             if 'place' in data:
@@ -340,11 +342,11 @@ class Ordinance():
                 self.date = data['date']['formal']
             if 'templeCode' in data:
                 self.temple_code = data['templeCode']
-            if data['status'] == 'http://familysearch.org/v1/Completed':
+            if data['status'] == u'http://familysearch.org/v1/Completed':
                 self.status = 'COMPLETED'
-            if data['status'] == 'http://familysearch.org/v1/Cancelled':
+            if data['status'] == u'http://familysearch.org/v1/Cancelled':
                 self.status = 'CANCELED'
-            if data['status'] == 'http://familysearch.org/v1/InProgress':
+            if data['status'] == u'http://familysearch.org/v1/InProgress':
                 self.status = 'SUBMITTED'
 
     def print(self, file=sys.stdout):
@@ -458,13 +460,13 @@ class Indi:
         data = fs.get_url(url)['persons'][0]['ordinances']
         if data:
             for o in data:
-                if o['type'] == 'http://lds.org/Baptism':
+                if o['type'] == u'http://lds.org/Baptism':
                     self.baptism = Ordinance(o)
-                if o['type'] == 'http://lds.org/Confirmation':
+                if o['type'] == u'http://lds.org/Confirmation':
                     self.confirmation = Ordinance(o)
-                if o['type'] == 'http://lds.org/Endowment':
+                if o['type'] == u'http://lds.org/Endowment':
                     self.endowment = Ordinance(o)
-                if o['type'] == 'http://lds.org/SealingChildToParents':
+                if o['type'] == u'http://lds.org/SealingChildToParents':
                     self.sealing_child = Ordinance(o)
 
     # retrieve parents
@@ -593,7 +595,8 @@ class Fam:
             self.num = Fam.counter
         self.husb_fid = husb if husb else None
         self.wife_fid = wife if wife else None
-        self.husb_num = self.wife_num = self.fid = self.marrdate = self.marrplac = None
+        self.husb_num = self.wife_num = self.fid = None
+        self.marriage_facts = set()
         self.sealing_spouse = None
         self.chil_fid = set()
         self.chil_num = set()
@@ -612,15 +615,8 @@ class Fam:
             url = 'https://familysearch.org/platform/tree/couple-relationships/' + self.fid + '.json'
             data = fs.get_url(url)
             if data and 'facts' in data['relationships'][0]:
-                x = data['relationships'][0]['facts'][0]
-                self.marrdate = x['date']['original'] if 'date' in x and 'original' in x['date'] else None
-                self.marrplac = x['place']['original'] if 'place' in x and 'original' in x['place'] else None
-            else:
-                self.marrdate = self.marrplac = None
-            notes = fs.get_url(data['relationships'][0]['links']['notes']['href'])
-            if notes:
-                for n in notes['relationships'][0]['notes']:
-                    self.notes.add(Note('===' + n['subject'] + '===\n' + n['text'] + '\n'))
+                for x in data['relationships'][0]['facts']:
+                    self.marriage_facts.add(Fact(x))
             if data and 'sources' in data['relationships'][0]:
                 for y in data['relationships'][0]['sources']:
                     json = fs.get_url(y['links']['description']['href'])['sourceDescriptions'][0]
@@ -628,6 +624,10 @@ class Fam:
                         self.sources.add((Source.add_source(json), y['attribution']['changeMessage']))
                     else:
                         self.sources.add((Source(json),))
+            notes = fs.get_url(data['relationships'][0]['links']['notes']['href'])
+            if notes:
+                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):
@@ -649,12 +649,19 @@ class Fam:
             file.write('1 WIFE @I' + str(self.wife_num) + '@\n')
         for num in self.chil_num:
             file.write('1 CHIL @I' + str(num) + '@\n')
-        if self.marrdate or self.marrplac:
-            file.write('1 MARR\n')
-            if self.marrdate:
-                file.write('2 DATE ' + self.marrdate + '\n')
-            if self.marrplac:
-                file.write('2 PLAC ' + self.marrplac + '\n')
+        for o in self.marriage_facts:
+            if o.type == u'http://gedcomx.org/Marriage':
+                file.write('1 MARR\n')
+            if o.type == u'http://gedcomx.org/Divorce':
+                file.write('1 DIV\n')
+            if o.type == u'http://gedcomx.org/Annulment':
+                file.write('1 ANUL\n')
+            if o.type == u'http://gedcomx.org/CommonLawMarriage':
+                file.write('1 _COML\n')
+            if o.date:
+                file.write('2 DATE ' + o.date + '\n')
+            if o.place:
+                file.write('2 PLAC ' + o.place + '\n')
         if self.sealing_spouse:
             file.write('1 SLGS\n')
             self.sealing_spouse.print(file)
index a5e30124d5cd073b5a570544964785452472482d..4eef14a8b178a09a4a62ed8ff0c8469fd3668afd 100755 (executable)
@@ -139,8 +139,8 @@ class Gedcom:
                 self.fam[self.num].wife_num = int(self.data[2:len(self.data) - 1])
             elif self.tag == 'CHIL':
                 self.fam[self.num].chil_num.add(int(self.data[2:len(self.data) - 1]))
-            elif self.tag == 'MARR':
-                self.__get_marr()
+            elif self.tag in ('MARR', 'DIV', 'ANUL', '_COML'):
+                self.fam[self.num].marriage_facts.add(self.__get_marr())
             elif self.tag == 'SLGS':
                 self.fam[self.num].sealing_spouse = self.__get_ordinance()
             elif self.tag == '_FSFTID':
@@ -221,12 +221,26 @@ class Gedcom:
         self.flag = True
 
     def __get_marr(self):
+        fact = Fact()
+        if self.tag == 'MARR':
+            fact.type = 'http://gedcomx.org/Marriage'
+        elif self.tag == 'DIV':
+            fact.type = 'http://gedcomx.org/Divorce'
+        elif self.tag == 'ANUL':
+            fact.type = 'http://gedcomx.org/Annulment'
+        elif self.tag == '_COML':
+            fact.type = 'http://gedcomx.org/CommonLawMarriage'
         while self.__get_line() and self.level > 1:
             if self.tag == 'DATE':
-                self.fam[self.num].marrdate = self.data
+                fact.date = self.data
             elif self.tag == 'PLAC':
-                self.fam[self.num].marrplac = self.data
+                fact.place = self.data
+            elif self.tag == 'NOTE':
+                num = int(self.data[2:len(self.data) - 1])
+                self.note[num] = Note(num=num)
+                fact.note = (self.note[num])
         self.flag = True
+        return fact
 
     def __get_fact(self):
         fact = Fact()
@@ -380,8 +394,7 @@ if __name__ == '__main__':
                 tree.fam[(husb, wife)] = Fam(husb, wife, fam_counter)
             tree.fam[(husb, wife)].chil_fid |= ged.fam[num].chil_fid
             tree.fam[(husb, wife)].fid = ged.fam[num].fid
-            tree.fam[(husb, wife)].marrdate = ged.fam[num].marrdate
-            tree.fam[(husb, wife)].marrplac = ged.fam[num].marrplac
+            tree.fam[(husb, wife)].marriage_facts = ged.fam[num].marriage_facts
             tree.fam[(husb, wife)].notes = ged.fam[num].notes
             tree.fam[(husb, wife)].sources = ged.fam[num].sources
             tree.fam[(husb, wife)].sealing_spouse = ged.fam[num].sealing_spouse