Пример #1
0
    def try_get_solution(self):
        replaced = [
            self.__replace(x) for x in [
                self.lat_deg, self.lat_min, self.lat_min_2, self.lon_deg,
                self.lon_min, self.lon_min_2
            ]
        ]
        self.replaced_result = ("%%s%s %s.%s %%s%s %s.%s" %
                                tuple(replaced)) % (self.ns, self.ew)
        results = [self.resolve(x) for x in replaced]

        for i in range(len(results)):
            if len(results[i]) not in self.EXPECTED_LENGTHS[i]:
                self.warnings.append(
                    self.WARNING_WRONG_LENGTH % (len(results[i]), " or ".join(
                        [str(x)
                         for x in self.EXPECTED_LENGTHS[i]]), results[i]))

        result = ("%%s%s %s.%s %%s%s %s.%s" % tuple(results)) % (self.ns,
                                                                 self.ew)
        #print self.replaced_result
        try:
            self.result = geo.try_parse_coordinate(result)
            self.result.name = self.orig
        except (Exception):
            self.warnings.append(self.WARNING_CANNOT_PARSE % result)
            logger.warning(self.WARNING_CANNOT_PARSE % result)
            self.result = False
Пример #2
0
 def save(self, after_name, after_calc):
     try:
         geo.try_parse_coordinate(after_calc)
         res = "Coordinate saved."
     except Exception:
         res = "Calc string saved."
     if self.__case in [0, 3]:
         value = after_calc
         id = self.__source_id
     elif self.__case == 2:
         value = (self.__coordinate.signature, after_calc)
         id = None
     elif self.__case == 4:
         value = (self.__info['value'][0], after_calc)
         id = self.__source_id
     else:
         raise Exception("Illegal call. Case is %d. For case in (1,5) call saveCoordinate!" % self.__case)
     self.__cachewrapper._geocache.set_user_coordinate(self.__ctype, value, after_name, id)
     logger.debug("Now saving user coordinates?")
     self.__cachewrapper.save_user_coordinates()
     return res
Пример #3
0
 def try_get_solution(self):
     replaced = [self.__replace(x) for x in [self.lat_deg, self.lat_min, self.lat_min_2, self.lon_deg, self.lon_min, self.lon_min_2]]
     self.replaced_result = ("%%s%s %s.%s %%s%s %s.%s" % tuple(replaced)) % (self.ns, self.ew)
     results = [self.resolve(x) for x in replaced]
     
     for i in range(len(results)):
         if len(results[i]) not in self.EXPECTED_LENGTHS[i]:
             self.warnings.append(self.WARNING_WRONG_LENGTH % (len(results[i]), " or ".join([str(x) for x in self.EXPECTED_LENGTHS[i]]), results[i]))
     
     result = ("%%s%s %s.%s %%s%s %s.%s" % tuple(results)) % (self.ns, self.ew)
     #print self.replaced_result
     try:
         self.result = geo.try_parse_coordinate(result)
         self.result.name = self.orig                
     except (Exception):
         self.warnings.append(self.WARNING_CANNOT_PARSE % result)
         logger.warning(self.WARNING_CANNOT_PARSE % result)
         self.result = False
Пример #4
0
        except Exception, e:
            logger.error("Could not find type!")
            raise e    
        
        # Short Description - Long Desc. is added after the image handling (see below)
        try:
            coordinate.shortdesc = doc.get_element_by_id('ctl00_ContentBody_ShortDescription').text_content()
        except KeyError, e:
            # happend when no short description is available
            logger.info("No short description available")
            coordinate.shortdesc = ''

        # Coordinate - may have been updated by the user; therefore retrieve it again
        try:
            text = doc.get_element_by_id('uxLatLon').text_content()
            coord = geo.try_parse_coordinate(text)
            coordinate.lat, coordinate.lon = coord.lat, coord.lon
        except KeyError, e:
            raise Exception("Could not find uxLatLon")
        except Exception, e:
            logger.error("Could not parse this coordinate: %r" % text)
            raise e
        
        # Size 
        try:
            # src is URL to image of the cache size
            # src.split('/')[-1].split('.')[0] is the basename minus extension
            coordinate.size = self._handle_size(basename(doc.cssselect('.CacheSize p span img')[0].get('src')))
        except Exception, e:
            logger.error("Could not find/parse size string")
            raise e
Пример #5
0
    def parse_coord(self):
        if not self.has_next():
            raise ParseError("Expected Coordinate but there was none.",
                             self.nt - 1)
        text = sys.argv[self.nt]
        self.nt += 1
        if text.startswith('q:'):
            query = text[2:]
            try:
                c = self.core.get_coord_by_name(query)
            except Exception, e:
                raise ParseError(e)
        else:
            try:
                c = geo.try_parse_coordinate(text)
            except Exception, e:
                raise ParseError(e)

        return c

    def parse_string(self):
        if not self.has_next():
            raise ParseError("Expected some Input, found nothing", self.nt - 1)
        text = sys.argv[self.nt]
        self.nt += 1
        return text.strip()

    def parse_int(self):
        if not self.has_next():
            raise ParseError("Expected a number, found nothing.", self.nt - 1)
Пример #6
0
    def parse_coord(self):
        if not self.has_next():
            raise ParseError("Expected Coordinate but there was none.",
                             self.nt - 1)
        text = sys.argv[self.nt]
        self.nt += 1
        if text.startswith('q:'):
            query = text[2:]
            try:
                c = self.core.get_coord_by_name(query)
            except Exception, e:
                raise ParseError(e)
        else:
            try:
                c = geo.try_parse_coordinate(text)
            except Exception, e:
                raise ParseError(e)

        return c

    def parse_string(self):
        if not self.has_next():
            raise ParseError("Expected some Input, found nothing", self.nt - 1)
        text = sys.argv[self.nt]
        self.nt += 1
        return text.strip()

    def parse_int(self):
        if not self.has_next():
            raise ParseError("Expected a number, found nothing.", self.nt - 1)