]> Nutra Git (v1) - gamesguru/getmyancestors.git/commitdiff
Fix some bugs
authorBenoît Fontaine <benoitfontaine.ba@gmail.com>
Wed, 25 Oct 2017 21:52:13 +0000 (23:52 +0200)
committerBenoît Fontaine <benoitfontaine.ba@gmail.com>
Wed, 25 Oct 2017 21:52:13 +0000 (23:52 +0200)
.gitignore
getmyancestors.py
mergemyancestors.py

index e0003f502ac4eaa33b43267098b5147f40e67732..282a1530f06e48005924fbdeac541af28df406ef 100644 (file)
@@ -1,2 +1,3 @@
 *.pyc
-*.ged
\ No newline at end of file
+*.ged
+*.log
\ No newline at end of file
index c8b04941a4636cda756d97e4c8492ec50e02025b..3256b54613ab98372f12084d0e69f0cd0e45e50a 100755 (executable)
@@ -196,7 +196,7 @@ class Session:
                 if self.verbose:
                     self.logfile.write('[' + time.strftime("%Y-%m-%d %H:%M:%S") + ']: HTTPError\n')
                 if 'message' in fr.json()['errors'][0] and fr.json()['errors'][0]['message'] == u'Unable to get ordinances.':
-                    self.logfile.write('Unable to get ordinances. Try without option -c.\n')
+                    self.logfile.write('Unable to get ordinances. Try with an LDS account or without option -c.\n')
                     exit()
                 time.sleep(self.timeout)
                 continue
@@ -242,8 +242,8 @@ class Source:
         else:
             Source.counter += 1
             self.num = Source.counter
-        if tree:
-            tree.sources.add(self)
+        if tree and data:
+            tree.sources[data['id']] = self
 
         self.url = self.citation = self.title = self.fid = None
         self.notes = set()
@@ -264,11 +264,11 @@ class Source:
     def print(self, file=sys.stdout):
         file.write('0 @S' + str(self.num) + '@ SOUR \n')
         if self.title:
-            file.write('1 TITL ' + self.title + '\n')
+            file.write('1 TITL ' + self.title.replace('\n', '\n2 CONT ') + '\n')
         if self.citation:
-            file.write('1 AUTH ' + self.citation + '\n')
+            file.write('1 AUTH ' + self.citation.replace('\n', '\n2 CONT ') + '\n')
         if self.url:
-            file.write('1 PUBL ' + self.url + '\n')
+            file.write('1 PUBL ' + self.url.replace('\n', '\n2 CONT ') + '\n')
         for n in self.notes:
             n.link(file, 1)
         file.write('1 REFN ' + self.fid + '\n')
@@ -293,6 +293,19 @@ class Fact:
             if 'changeMessage' in data['attribution']:
                 self.note = Note(data['attribution']['changeMessage'], tree)
 
+    def print(self, file=sys.stdout, key=None):
+        if key:
+            file.write('1 ' + key)
+            if self.value:
+                file.write(' ' + self.value)
+            file.write('\n')
+            if self.date:
+                file.write('2 DATE ' + self.date + '\n')
+            if self.place:
+                file.write('2 PLAC ' + self.place + '\n')
+            if self.note:
+                self.note.link(file, 2)
+
 
 class Name:
 
@@ -573,13 +586,7 @@ class Indi:
             if self.buriplac:
                 file.write('2 PLAC ' + self.buriplac + '\n')
         for o in self.physical_descriptions:
-            file.write('1 DSCR ' + o.value + '\n')
-            if o.date:
-                file.write('2 DATE ' + o.date + '\n')
-            if o.place:
-                file.write('2 PLAC ' + o.place + '\n')
-            if o.note:
-                o.note.link(file, 2)
+            o.print(file, 'DSCR')
         if self.baptism:
             file.write('1 BAPL\n')
             self.baptism.print(file)
@@ -597,21 +604,9 @@ class Indi:
         for num in self.famc_num:
             file.write('1 FAMC @F' + str(num) + '@\n')
         for o in self.occupations:
-            file.write('1 OCCU ' + o.value + '\n')
-            if o.date:
-                file.write('2 DATE ' + o.date + '\n')
-            if o.place:
-                file.write('2 PLAC ' + o.place + '\n')
-            if o.note:
-                o.note.link(file, 2)
+            o.print(file, 'OCCU')
         for o in self.military:
-            file.write('1 _MILT ' + o.value + '\n')
-            if o.date:
-                file.write('2 DATE ' + o.date + '\n')
-            if o.place:
-                file.write('2 PLAC ' + o.place + '\n')
-            if o.note:
-                o.note.link(file, 2)
+            o.print(file, '_MILT')
         file.write('1 _FSFTID ' + self.fid + '\n')
         for o in self.notes:
             o.link(file)
@@ -699,20 +694,17 @@ class Fam:
         for num in self.chil_num:
             file.write('1 CHIL @I' + str(num) + '@\n')
         for o in self.marriage_facts:
+            key = ''
             if o.type == u'http://gedcomx.org/Marriage':
-                file.write('1 MARR\n')
+                key = 'MARR'
             if o.type == u'http://gedcomx.org/Divorce':
-                file.write('1 DIV\n')
+                key = 'DIV'
             if o.type == u'http://gedcomx.org/Annulment':
-                file.write('1 ANUL\n')
+                key = 'ANUL'
             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 o.note:
-                file.write('2 NOTE @N' + str(o.note.num) + '@\n')
+                key = 'COML'
+            if key:
+                o.print(file, key)
         if self.sealing_spouse:
             file.write('1 SLGS\n')
             self.sealing_spouse.print(file)
@@ -733,7 +725,7 @@ class Tree:
         self.indi = dict()
         self.fam = dict()
         self.notes = set()
-        self.sources = set()
+        self.sources = dict()
 
     # add individual to the family tree
     def add_indi(self, fid):
@@ -801,9 +793,8 @@ class Tree:
     # Find source by fid
     def add_source(self, data=None):
         if data:
-            for s in self.sources:
-                if s.fid == data['id']:
-                    return s
+            if data['id'] in self.sources:
+                return self.sources[data['id']]
             return Source(data, self)
         return False
 
@@ -827,11 +818,8 @@ class Tree:
             self.indi[fid].print(file)
         for husb, wife in sorted(self.fam, key=lambda x: self.fam.__getitem__(x).num):
             self.fam[(husb, wife)].print(file)
-        sources = sorted(self.sources, key=lambda x: x.num)
-        for i, s in enumerate(sources):
-            if i > 0:
-                if s.num == sources[i - 1].num:
-                    continue
+        sources = sorted(self.sources.values(), key=lambda x: x.num)
+        for s in sources:
             s.print(file)
         notes = sorted(self.notes, key=lambda x: x.num)
         for i, n in enumerate(notes):
index 6600776cadc2d09d6bbad7f08f24d7fe44ad5942..17805461589e6277c11ebe14f7d6511a32c2940b 100755 (executable)
@@ -71,7 +71,7 @@ class Gedcom:
             elif self.tag == 'SOUR':
                 self.num = int(self.pointer[2:len(self.pointer) - 1])
                 if self.num not in self.sour:
-                    self.sour[self.num] = Source(tree=self.tree, num=self.num)
+                    self.sour[self.num] = Source(num=self.num)
                 self.__get_source()
             else:
                 continue
@@ -279,6 +279,10 @@ class Gedcom:
                 self.sour[self.num].url = self.data
             elif self.tag == 'REFN':
                 self.sour[self.num].fid = self.data
+                if self.data in self.tree.sources:
+                    self.sour[self.num] = self.tree.sources[self.data]
+                else:
+                    self.tree.sources[self.data] = self.sour[self.num]
             elif self.tag == 'NOTE':
                 num = int(self.data[2:len(self.data) - 1])
                 if num not in self.note:
@@ -289,7 +293,7 @@ class Gedcom:
     def __get_link_source(self):
         num = int(self.data[2:len(self.data) - 1])
         if num not in self.sour:
-            self.sour[num] = Source(tree=self.tree, num=num)
+            self.sour[num] = Source(num=num)
         page = None
         while self.__get_line() and self.level > 1:
             if self.tag == 'PAGE':
@@ -431,17 +435,6 @@ if __name__ == '__main__':
         else:
             n.num = tree.notes[i - 1].num + 1
 
-    # merge sources by fid
-    tree.sources = sorted(tree.sources, key=lambda x: x.fid)
-    for i, n in enumerate(tree.sources):
-        if i == 0:
-            n.num = 1
-            continue
-        if n.fid == tree.sources[i - 1].fid:
-            n.num = tree.sources[i - 1].num
-        else:
-            n.num = tree.sources[i - 1].num + 1
-
     # compute number for family relationships and print GEDCOM file
     tree.reset_num()
     tree.print(args.o)