def _parseJidLocTime(self, mess, args, parse_date = True): jid = mess.getFrom().getStripped() args = args.strip() if args is None or len(args) == 0: return (jid, None, None) loc = None dt = None lng = None lat = None loc_name = None pargs = self._arg_re.split(args.strip()) if pargs is not None: for arg in pargs: parsed_arg = TypeDetector(arg) if parse_date and parsed_arg.getType() == TypeDetector.DATE: if dt is not None: raise CmdError('Invalid double date argument: ' + arg) dt = parsed_arg.getTypeValue() elif parsed_arg.getType() == TypeDetector.LOCATION_LONG: if lng is not None: raise CmdError('Invalid double longitude argument: ' + arg) lng = parsed_arg.getTypeValue() elif parsed_arg.getType() == TypeDetector.LOCATION_LAT: if lat is not None: raise CmdError('Invalid double latitude argument: ' + arg) lat = parsed_arg.getTypeValue() elif parsed_arg.getType() == TypeDetector.STRING: if loc_name is not None: raise CmdError('Invalid double location name argument: ' + arg) loc_name = parsed_arg.getValue() else: raise CmdError('Invalid argument: ' + arg) if (lng is not None or lat is not None) and loc_name is not None: raise CmdError('Invalid arguments. Please specify only one of longitude/latitude or location name.') if lng is not None and lat is None: raise CmdError('Invalid argument. Latitude missing.') if lng is None and lat is not None: raise CmdError('Invalid argument. Latitude missing.') if lng is not None: loc = Location(None, None, None, lng, lat) elif loc_name is not None: loc = Location(None, None, loc_name, None, None) return (jid, loc, dt)
def _doAddLoc(self, c, user, loc_name, sval1, sval2): """ Add location to list of locations. It reads geographic position in angle or geo format """ val1 = TypeDetector(sval1) val2 = TypeDetector(sval2) lng = 0.0 lat = 0.0 if val1.getType() == TypeDetector.FLOAT: if val2.getType() == TypeDetector.FLOAT: lng = val1.getTypeValue() lat = val2.getTypeValue() else: return 'Invalid argument: "' + sval2 + '". Number is expected.' elif val1.getType() == TypeDetector.LOCATION_LONG: if val2.getType() == TypeDetector.LOCATION_LAT: lng = val1.getTypeValue() lat = val2.getTypeValue() else: return 'Invalid argument: "' + sval2 + u'". Latitude expected. Example: 15??3\'53.856"E' elif val1.getType() == TypeDetector.LOCATION_LAT: if val2.getType() == TypeDetector.LOCATION_LONG: lat = val1.getTypeValue() lng = val2.getTypeValue() else: return 'Invalid argument: "' + sval2 + u'". Longitude expected. Example: 50??46\'1.655"N' else: return 'Invalid format of argument value: "' + sval1 + '". Use help for .' loc = user.getLocationByName(c, loc_name) if loc is None: user_locations = user.getUserLocationList(c) if len(user_locations) < self.MAX_USER_LOCATIONS: loc = user.createLocation(c, loc_name, lng, lat) reply = 'Location "' + loc.getInfo() + '" added.' # set default location if it is a first one if len(user_locations) == 0: user.setDefaultLocation(c, loc) reply += ' Location set as default location.' else: reply = 'Add location failed. Number of user locations exceeded limit ' + self.MAX_USER_LOCATIONS else: reply = 'Location "' + loc.getInfo() + '" already exists.' return reply