def get_temperature(self, location: GeoLocation) -> Temperature: ''' this last service retrive the result on fahrenheit temp unit, but the AverageTemperature primitive converts to a single unit begore to resolve the average: (5 celsius = 41 fahrenheit) ''' return Temperature('five', 41, TemperatureUnit.make_fahrenheit())
def conversion_unit(self) -> TemperatureUnit: if self.__conversion_unit: return self.__conversion_unit if settings.AVERAGE_CONVERSION_UNIT == 'C': self.__conversion_unit = TemperatureUnit.make_celsius() if settings.AVERAGE_CONVERSION_UNIT == 'F': self.__conversion_unit = TemperatureUnit.make_fahrenheit() if not self.__conversion_unit: import pdb pdb.set_trace() raise Exception('Conversion unit not configured !!') return self.__conversion_unit
def get_temperature(self, location: GeoLocation) -> Temperature: values = { 'lat': location.latitude, 'lon': location.longitude, } payload = json.dumps(values).encode('ascii') url_endpoint = '%s/weatherdotcom' % self.__BASE_URL weather_request = request.Request(url_endpoint, payload) weather_request.add_header('Content-Type', 'application/json') with request.urlopen(weather_request) as response: data = json.load(response) return Temperature( 'weatherdotcom', float( data['query']['results']['channel']['condition']['temp']), TemperatureUnit.make_fahrenheit())