From f026be8a893ba35d2414f8332dd6aa727a3fe50c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Fontaine?= Date: Sat, 6 Jan 2018 10:48:35 +0100 Subject: [PATCH] Fix missing references bug due to asynchronous requests --- getmyancestors.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/getmyancestors.py b/getmyancestors.py index 79379e4..dc854a8 100755 --- a/getmyancestors.py +++ b/getmyancestors.py @@ -302,12 +302,11 @@ class Source: else: Source.counter += 1 self.num = Source.counter - if tree and data: - tree.sources[data['id']] = self self.url = self.citation = self.title = self.fid = None self.notes = set() + def get_data(self, data): if data: self.fid = data['id'] if 'about' in data: @@ -474,6 +473,7 @@ class Indi: else: Indi.counter += 1 self.num = Indi.counter + self.downloaded = False self.fid = fid self.tree = tree self.famc_fid = set() @@ -482,6 +482,7 @@ class Indi: self.fams_num = set() self.name = None self.gender = None + self.parents = self.children = self.spouses = None self.baptism = self.confirmation = self.endowment = self.sealing_child = None self.nicknames = set() self.facts = set() @@ -491,7 +492,10 @@ class Indi: self.notes = set() self.sources = set() self.memories = set() - if fid and tree and tree.fs: + + def get_data(self): + if fid and tree and tree.fs and not self.downloaded: + self.downloaded = True url = 'https://familysearch.org/platform/tree/persons/%s.json' % self.fid data = tree.fs.get_url(url) if data: @@ -536,10 +540,6 @@ class Indi: for y in data['sourceDescriptions']: self.memories.add(Memorie(y)) - self.parents = None - self.children = None - self.spouses = None - # add a fams to the individual def add_fams(self, fams): if fams not in self.fams_fid: @@ -783,6 +783,7 @@ class Tree: def add_indi(self, fid): if fid and fid not in self.indi: self.indi[fid] = Indi(fid, self) + self.indi[fid].get_data() # add family to the family tree def add_fam(self, father, mother): @@ -851,7 +852,9 @@ class Tree: return self.sources[fid] data = self.fs.get_url('https://familysearch.org/platform/sources/descriptions/%s.json' % fid) if data: - return Source(data['sourceDescriptions'][0], self) + self.sources[data['sourceDescriptions'][0]['id']] = Source(self) + self.sources[data['sourceDescriptions'][0]['id']].get_data(data['sourceDescriptions'][0]) + return self.sources[data['sourceDescriptions'][0]['id']] return False def reset_num(self): -- 2.52.0