From: BenoƮt Fontaine Date: Thu, 7 Dec 2017 11:01:37 +0000 (+0100) Subject: Update mergemyancestors, fix CONT memorie bug X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=a32be06d8cd402e4051e9516e31c6bef02a908b3;p=gamesguru%2Fgetmyancestors.git Update mergemyancestors, fix CONT memorie bug --- diff --git a/getmyancestors.py b/getmyancestors.py index 06f5783..1be2187 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -308,19 +308,20 @@ class Fact: class Memorie: - def __init__(self, data=None, tree=None): + def __init__(self, data=None): self.description = self.url = None if data and 'links' in data: self.url = data['links']['alternate'][0]['href'] if 'titles' in data: self.description = data['titles'][0]['value'] if 'descriptions' in data: - self.description = (self.description or '') + '\n' + data['descriptions'][0]['value'] + self.description = ('' if not self.description else self.description + '\n') + data['descriptions'][0]['value'] + # self.description = (self.description or '') + '\n' + data['descriptions'][0]['value'] def print(self, file=sys.stdout): file.write('1 OBJE\n2 FORM URL\n') if self.description: - file.write('2 TITL ' + self.description.replace('\n', '\n1 CONT ') + '\n') + file.write('2 TITL ' + self.description.replace('\n', '\n2 CONT ') + '\n') if self.url: file.write('2 FILE ' + self.url + '\n') @@ -479,7 +480,7 @@ class Indi: data = tree.fs.get_url(url) if data and 'sourceDescriptions' in data: for y in data['sourceDescriptions']: - self.memories.add(Memorie(y, tree)) + self.memories.add(Memorie(y)) self.parents = None self.children = None diff --git a/mergemyancestors.py b/mergemyancestors.py index 1780546..85d9ac5 100755 --- a/mergemyancestors.py +++ b/mergemyancestors.py @@ -29,7 +29,7 @@ import sys import argparse # local import -from getmyancestors import Indi, Fam, Tree, Name, Note, Fact, Source, Ordinance +from getmyancestors import Indi, Fam, Tree, Name, Note, Fact, Source, Ordinance, Memorie sys.path.append(os.path.dirname(sys.argv[0])) @@ -133,6 +133,8 @@ class Gedcom: self.indi[self.num].notes.add(self.note[num]) elif self.tag == 'SOUR': self.indi[self.num].sources.add(self.__get_link_source()) + elif self.tag == 'OBJE': + self.indi[self.num].memories.add(self.__get_memorie()) self.flag = True def __get_fam(self): @@ -269,14 +271,24 @@ class Gedcom: fact.note = self.note[num] self.flag = True + def __get_text(self): + text = self.data + while self.__get_line(): + if self.tag == 'CONT': + text += '\n' + self.data + else: + break + self.flag = True + return text + def __get_source(self): while self.__get_line() and self.level > 0: if self.tag == 'TITL': - self.sour[self.num].title = self.data + self.sour[self.num].title = self.__get_text() elif self.tag == 'AUTH': - self.sour[self.num].citation = self.data + self.sour[self.num].citation = self.__get_text() elif self.tag == 'PUBL': - self.sour[self.num].url = self.data + self.sour[self.num].url = self.__get_text() elif self.tag == 'REFN': self.sour[self.num].fid = self.data if self.data in self.tree.sources: @@ -297,20 +309,26 @@ class Gedcom: page = None while self.__get_line() and self.level > 1: if self.tag == 'PAGE': - page = self.data - if self.tag == 'CONT': - page += '\n' + self.data + page = self.__get_text() self.flag = True if page: return (self.sour[num], page) else: return (self.sour[num],) + def __get_memorie(self): + memorie = Memorie() + pdb = False + while self.__get_line() and self.level > 1: + if self.tag == 'TITL': + memorie.description = self.__get_text() + elif self.tag == 'FILE': + memorie.url = self.data + self.flag = True + return memorie + def __get_note(self): - self.note[self.num].text = self.data - while self.__get_line() and self.level > 0: - if self.tag == 'CONT': - self.note[self.num].text += '\n' + self.data + self.note[self.num].text = self.__get_text() self.flag = True def __get_ordinance(self): @@ -404,6 +422,7 @@ if __name__ == '__main__': tree.indi[fid].military = ged.indi[num].military tree.indi[fid].notes = ged.indi[num].notes tree.indi[fid].sources = ged.indi[num].sources + tree.indi[fid].memories = ged.indi[num].memories tree.indi[fid].baptism = ged.indi[num].baptism tree.indi[fid].confirmation = ged.indi[num].confirmation tree.indi[fid].endowment = ged.indi[num].endowment