Exemplo n.º 1
0
    def _analyze_track(self, track, namespaces):
        ns_dict = {
            'gps':
            'https://github.com/StevenMohr/gpsies-xml/schema/database.xsd'
        }
        try:
            dLink = None
            downloadLinks = track.xpath("//downloadLink/text()")

            trackXML = TrackExtract(
                track_element_xml=track).analyze(namespaces)
            if namespaces:
                id = trackXML.xpath("//gps:uid/text()", namespaces=ns_dict)[0]
            else:
                id = trackXML.xpath("//uid/text()")[0]
            for link in downloadLinks:
                if id in link:
                    dLink = link
                    break
            connection = urlopen(dLink, timeout=10)
            answer = connection.read()
            connection.close()
            waypoints = KMLExtract(answer).analyze(namespaces)
            trackXML.append(waypoints)
            # self._xsd_schema.assertValid(trackXML) Uncomment to get description of validation errors
            if (not namespaces) or (self._xsd_schema.validate(trackXML)
                                    ):  # Only validate if namespaces is true
                result = etree.tostring(trackXML)
                self._session.add('database2/tracks', result)
            else:
                print "Validation failed: " + etree.tostring(trackXML)
        except IOError as e:
            print e
Exemplo n.º 2
0
 def test_analyze_long(self):
     analyze = KMLExtract(
         open(
             pkg_resources.resource_filename(
                 "gpsies_importer.tests.extract",
                 "54KmTeltowkanal.kml")).read())
     result = analyze.analyze()
     assert len(result) > 0
Exemplo n.º 3
0
 def test_analyze(self):
     analyze = KMLExtract(self.test_kml)
     result = analyze.analyze()
     self.assertGreater(len(result), 0, 'Result tree is empty!')
     self.assertEqual(
         etree.tostring(result),
         '<ns0:waypoints xmlns:ns0="https://github.com/StevenMohr/gpsies-xml/schema/database.xsd"><ns0:waypoint longitude="8.55" latitude="47.3666667"/></ns0:waypoints>',
         'waypoint sub-tree incorrect')