Beispiel #1
0
    def get_nearest_runway(self,
                           airport,
                           heading,
                           latitude=None,
                           longitude=None,
                           ils_freq=None,
                           hint=None):
        '''
        Returns the nearest runway from the specified airport using latitude,
        longitude, precision and ils frequency.

        :param airport: Either ICAO code, IATA code or database ID of airport.
        :type airport: int or str
        :param heading: Magnetic heading.
        :type heading: int # Q: could it be float?
        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :param ils_freq: ILS Localizer frequency of the runway in KHz.
        :type ils_freq: float # Q: could/should it be int?
        :param hint: Whether we are looking up a runway for 'takeoff',
                'landing', or 'approach'.
        :type hint: str
        :raises NotFoundError: If the runway cannot be found.
        :raises InvalidAPIInputError: If latitude, longitude or heading are out
                of bounds.
        :returns: Runway info in the format {'ident': '27*', 'items': [{# ...},
                {# ...},]}, 'ident' is either specific ('09L') or generalised
                ('09*').  'items' is a list of matching runways.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/%(airport)s/runway/nearest.json' % {
            'airport': airport,
            'base_url': BASE_URL.rstrip('/'),
        }

        params = {'heading': heading}
        if latitude and longitude:
            params['ll'] = '%f,%f' % (latitude, longitude)
        if ils_freq:
            # While ILS frequency is recorded in MHz, the API expects KHz.
            params['ilsfreq'] = int(ils_freq * 1000)
        if hint in ['takeoff', 'landing', 'approach']:
            params['hint'] = hint
        url += '?' + urllib.urlencode(params)
        runway = self._attempt_request(url)['runway']
        if not runway.get('end'):
            raise IncompleteEntryError(
                "Runway ident '%s' at '%s' has no end" %
                (runway.get('identifier', 'unknown'), airport))
        return runway
    def get_nearest_runway(self, airport, heading, latitude=None,
                           longitude=None, ils_freq=None, hint=None):
        '''
        Returns the nearest runway from the specified airport using latitude,
        longitude, precision and ils frequency.

        :param airport: Either ICAO code, IATA code or database ID of airport.
        :type airport: int or str
        :param heading: Magnetic heading.
        :type heading: int # Q: could it be float?
        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :param ils_freq: ILS Localizer frequency of the runway in KHz.
        :type ils_freq: float # Q: could/should it be int?
        :param hint: Whether we are looking up a runway for 'takeoff',
                'landing', or 'approach'.
        :type hint: str
        :raises NotFoundError: If the runway cannot be found.
        :raises InvalidAPIInputError: If latitude, longitude or heading are out
                of bounds.
        :returns: Runway info in the format {'ident': '27*', 'items': [{# ...},
                {# ...},]}, 'ident' is either specific ('09L') or generalised
                ('09*').  'items' is a list of matching runways.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/%(airport)s/runway/nearest.json' % {
            'airport': airport,
            'base_url': BASE_URL.rstrip('/'),
        }

        params = {'heading': heading}
        if latitude and longitude:
            params['ll'] = '%f,%f' % (latitude, longitude)
        if ils_freq:
            # While ILS frequency is recorded in MHz, the API expects KHz.
            params['ilsfreq'] = int(ils_freq * 1000)
        if hint in ['takeoff', 'landing', 'approach']:
            params['hint'] = hint
        url += '?' + urllib.urlencode(params)
        runway = self._attempt_request(url)['runway']
        if not runway.get('end'):
            raise IncompleteEntryError(
                "Runway ident '%s' at '%s' has no end" %
                (runway.get('identifier', 'unknown'), airport))
        return runway
    def get_analyser_profiles(self, tail_number):
        '''
        Will return analyser profiles enabled for an aircraft.

        :param tail_number: Aircraft tail number.
        :type tail_number: str
        :raises NotFoundError: If the aircraft cannot be found.
        :returns: Analyser profiles in (module_path, required) tuples.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/aircraft/%(tail_number)s/analyser_profiles/' % {
            'base_url': BASE_URL.rstrip('/'),
            'tail_number': tail_number,
        }
        return self.request(url)['analyser_profiles']
 def get_analyser_profiles(self, tail_number):
     '''
     Will return analyser profiles enabled for an aircraft.
     
     :param tail_number: Aircraft tail number.
     :type tail_number: str
     :raises NotFoundError: If the aircraft cannot be found.
     :returns: Analyser profiles in (module_path, required) tuples.
     :rtype: dict
     '''
     from analysis_engine.settings import BASE_URL
     url = '%(base_url)s/api/aircraft/%(tail_number)s/analyser_profiles/' % {
         'base_url': BASE_URL.rstrip('/'),
         'tail_number': tail_number,
     }
     return self._attempt_request(url)['analyser_profiles']
    def get_data_exports(self, tail_number):
        '''
        Will either return data exports configuration for an aircraft matching
        the tail number or raise an exception if one cannot be found.

        :param tail_number: Aircraft tail number.
        :type tail_number: str
        :raises NotFoundError: If the aircraft cannot be found.
        :returns: Aircraft info dictionary
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/data_exports/aircraft/%(tail_number)s/' % {
            'base_url': BASE_URL.rstrip('/'),
            'tail_number': tail_number,
        }
        return self.request(url)['data_exports']
    def get_airport(self, code):
        '''
        Will either return an airport matching the code or raise an exception
        if one cannot be found.

        :param code: Either the id, ICAO or IATA of the airport.
        :type code: int or str
        :raises NotFoundError: If the airport cannot be found.
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/%(code)s/' % {
            'base_url': BASE_URL.rstrip('/'),
            'code': code,
        }
        return self.request(url)['airport']
    def get_data_exports(self, tail_number):
        '''
        Will either return data exports configuration for an aircraft matching
        the tail number or raise an exception if one cannot be found.

        :param tail_number: Aircraft tail number.
        :type tail_number: str
        :raises NotFoundError: If the aircraft cannot be found.
        :returns: Aircraft info dictionary
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/data_exports/aircraft/%(tail_number)s/' % {
            'base_url': BASE_URL.rstrip('/'),
            'tail_number': tail_number,
        }
        return self._attempt_request(url)['data_exports']
    def get_airport(self, code):
        '''
        Will either return an airport matching the code or raise an exception
        if one cannot be found.

        :param code: Either the id, ICAO or IATA of the airport.
        :type code: int or str
        :raises NotFoundError: If the airport cannot be found.
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/%(code)s/' % {
            'base_url': BASE_URL.rstrip('/'),
            'code': code,
        }
        return self._attempt_request(url)['airport']
    def get_nearest_airport(self, latitude, longitude):
        '''
        Either returns the nearest airport to the specified latitude and
        longitude, or raises an exception if one cannot be found.

        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/nearest.json' % {
            'base_url': BASE_URL.rstrip('/'),
        }
        params = {'ll': '%f,%f' % (latitude, longitude)}
        return self.request(url, params=params)['airport']
    def get_nearest_airport(self, latitude, longitude):
        '''
        Either returns the nearest airport to the specified latitude and
        longitude, or raises an exception if one cannot be found.

        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/nearest.json' % {
            'base_url': BASE_URL.rstrip('/'),
        }
        params = {'ll': '%f,%f' % (latitude, longitude)}
        return self.request(url, params=params)['airport']
Beispiel #11
0
    def get_nearest_airport(self, latitude, longitude):
        '''
        Either returns the nearest airport to the specified latitude and
        longitude, or raises an exception if one cannot be found.

        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :raises InvalidAPIInputError: If latitude or longitude are out of
                bounds.
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/nearest.json?ll=%(ll)s' % {
            'base_url': BASE_URL.rstrip('/'),
            'll': '%f,%f' % (latitude, longitude),
        }
        return self._attempt_request(url)['airport']
    def get_nearest_airport(self, latitude, longitude):
        '''
        Either returns the nearest airport to the specified latitude and
        longitude, or raises an exception if one cannot be found.

        :param latitude: Latitude in decimal degrees.
        :type latitude: float
        :param longitude: Longitude in decimal degrees.
        :type longitude: float
        :raises InvalidAPIInputError: If latitude or longitude are out of
                bounds.
        :returns: Airport info dictionary.
        :rtype: dict
        '''
        from analysis_engine.settings import BASE_URL
        url = '%(base_url)s/api/airport/nearest.json?ll=%(ll)s' % {
            'base_url': BASE_URL.rstrip('/'),
            'll': '%f,%f' % (latitude, longitude),
        }
        return self._attempt_request(url)['airport']