]> Nutra Git (v2) - gamesguru/getmyancestors.git/commitdiff
Add map coordinates. Works with normalized places.
authorBenoît Fontaine <benoitfontaine.ba@gmail.com>
Wed, 10 Jan 2018 12:38:09 +0000 (13:38 +0100)
committerBenoît Fontaine <benoitfontaine.ba@gmail.com>
Wed, 10 Jan 2018 12:38:09 +0000 (13:38 +0100)
getmyancestors.py
mergemyancestors.py

index 5bb53129ce8c6c661a755a6edb5e2ec4d83940e2..1ec6cab25013337060151fecedb7a4882f63c24e 100755 (executable)
@@ -342,7 +342,7 @@ class Source:
 class Fact:
 
     def __init__(self, data=None, tree=None):
-        self.value = self.type = self.date = self.place = self.note = None
+        self.value = self.type = self.date = self.place = self.note = self.map = None
         if data:
             if 'value' in data:
                 self.value = data['value']
@@ -357,7 +357,10 @@ class Fact:
             if 'date' in data:
                 self.date = data['date']['original']
             if 'place' in data:
-                self.place = data['place']['original']
+                place = data['place']
+                self.place = place['original']
+                if 'description' in place and place['description'][1:] in tree.places:
+                    self.map = tree.places[place['description'][1:]]
             if 'changeMessage' in data['attribution']:
                 self.note = Note(data['attribution']['changeMessage'], tree)
             if self.type == 'http://gedcomx.org/Death' and not (self.date or self.place):
@@ -379,6 +382,9 @@ class Fact:
             file.write('2 DATE ' + self.date + '\n')
         if self.place:
             file.write('2 PLAC ' + self.place + '\n')
+        if self.map:
+            latitude, longitude = self.map
+            file.write('3 MAP\n4 LATI ' + latitude + '\n4 LONG ' + longitude + '\n')
         if self.note:
             self.note.link(file, 2)
 
@@ -754,6 +760,7 @@ class Tree:
         self.fam = dict()
         self.notes = list()
         self.sources = dict()
+        self.places = dict()
 
     # add individuals to the family tree
     def add_indis(self, fids):
@@ -771,6 +778,10 @@ class Tree:
             print(len(new_fids))
             data = self.fs.get_url('https://familysearch.org/platform/tree/persons.json?pids=' + ','.join(new_fids[:MAX_PERSONS]))
             if data:
+                if 'places' in data:
+                    for place in data['places']:
+                        if place['id'] not in self.places:
+                            self.places[place['id']] = (str(place['latitude']), str(place['longitude']))
                 loop.run_until_complete(add_datas(loop, data))
                 if 'childAndParentsRelationships' in data:
                     for rel in data['childAndParentsRelationships']:
index 1771249ff9050cfd707bdd88aabcd9af7d96a446..f8841e81f0bb5017206eb039704efc4adf67bff3 100755 (executable)
@@ -191,38 +191,6 @@ class Gedcom:
             self.indi[self.num].birthnames.add(name)
         self.flag = True
 
-    def __get_birt(self):
-        while self.__get_line() and self.level > 1:
-            if self.tag == 'DATE':
-                self.indi[self.num].birtdate = self.data
-            elif self.tag == 'PLAC':
-                self.indi[self.num].birtplac = self.data
-        self.flag = True
-
-    def __get_chr(self):
-        while self.__get_line() and self.level > 1:
-            if self.tag == 'DATE':
-                self.indi[self.num].chrdate = self.data
-            elif self.tag == 'PLAC':
-                self.indi[self.num].chrplac = self.data
-        self.flag = True
-
-    def __get_deat(self):
-        while self.__get_line() and self.level > 1:
-            if self.tag == 'DATE':
-                self.indi[self.num].deatdate = self.data
-            elif self.tag == 'PLAC':
-                self.indi[self.num].deatplac = self.data
-        self.flag = True
-
-    def __get_buri(self):
-        while self.__get_line() and self.level > 1:
-            if self.tag == 'DATE':
-                self.indi[self.num].buridate = self.data
-            elif self.tag == 'PLAC':
-                self.indi[self.num].buriplac = self.data
-        self.flag = True
-
     def __get_fact(self):
         fact = Fact()
         if self.tag != 'EVEN':
@@ -235,6 +203,8 @@ class Gedcom:
                 fact.date = self.data
             elif self.tag == 'PLAC':
                 fact.place = self.data
+            elif self.tag == 'MAP':
+                fact.map = self.__get_map()
             elif self.tag == 'NOTE':
                 if self.data[:12] == 'Description:':
                     fact.value = self.data[13:]
@@ -248,6 +218,17 @@ class Gedcom:
         self.flag = True
         return fact
 
+    def __get_map(self):
+        latitude = None
+        longitude = None
+        while self.__get_line() and self.level > 3:
+            if self.tag == 'LATI':
+                latitude = self.data
+            elif self.tag == 'LONG':
+                longitude = self.data
+        self.flag = True
+        return (latitude, longitude)
+
     def __get_text(self):
         text = self.data
         while self.__get_line():