示例#1
0
 def parse_json(self, json, data_type, time_period):
     self._type = self.extract_attribute(json, '$', data_type, time_period)
     self._wind_direction = self.extract_attribute(json, 'D', data_type,
                                                   time_period)
     self._temp_max = self.extract_attribute(json, 'Dm', data_type,
                                             time_period)
     self._temperature_feels_like_max = self.extract_attribute(
         json, 'FDm', data_type, time_period)
     self._wind_gust_noon = self.extract_attribute(json, 'Gn', data_type,
                                                   time_period)
     self._screen_relative_humidity_noon = self.extract_attribute(
         json, 'Hn', data_type, time_period)
     self._precipitation_probability = self.extract_attribute(
         json, 'PPd', data_type, time_period)
     self._wind_speed = self.extract_attribute(json, 'S', data_type,
                                               time_period)
     self._uv_index_max = self.extract_attribute(json, 'U', data_type,
                                                 time_period)
     if self._uv_index_max is not None:
         self._uv_guidance = metoffer.guidance_UV(int(self._uv_index_max))
     self._visibility_code = self.extract_attribute(json, 'V', data_type,
                                                    time_period)
     if self._visibility_code is not None:
         self._visibility_text = metoffer.VISIBILITY[self._visibility_code]
     self._weather_type_code = self.extract_attribute(
         json, 'W', data_type, time_period)
     if self._weather_type_code is not None:
         self._weather_type_text = metoffer.WEATHER_CODES[int(
             self._weather_type_code)]
示例#2
0
def SimpleExample():
    apikey = '7e2ecd8b-e840-4d06-8eba-5b48ff725cb0'
    data = getNearestLocationData(51.52054, -0.09773, apikey)

    print(data.name, data.lat, data.lon, data.elevation)
    pprint.pprint(data.data)

    for i in data.data:
        print(
            "{} - {}".format(i["timestamp"][0].strftime("%d %b, %H:%M"), metoffer.WEATHER_CODES[i["Weather Type"][0]]))

    print(metoffer.guidance_UV(data.data[0]["Max UV Index"][0]))
示例#3
0
 def parse_json(self, json_data, data_type, time_period):
     self._type = self.extract_attribute(json_data, '$', data_type, time_period)
     self._wind_direction = self.extract_attribute(json_data, 'D', data_type, time_period)
     self._temp_max = self.extract_attribute(json_data, 'Dm', data_type, time_period)
     self._temperature_feels_like_max = self.extract_attribute(json_data, 'FDm', data_type, time_period)
     self._wind_gust_noon = self.extract_attribute(json_data, 'Gn', data_type, time_period)
     self._screen_relative_humidity_noon = self.extract_attribute(json_data, 'Hn', data_type, time_period)
     self._precipitation_probability = self.extract_attribute(json_data, 'PPd', data_type, time_period)
     self._wind_speed = self.extract_attribute(json_data, 'S', data_type, time_period)
     self._uv_index_max = self.extract_attribute(json_data, 'U', data_type, time_period)
     if self._uv_index_max is not None:
         self._uv_guidance = metoffer.guidance_UV(int(self._uv_index_max))
     self._visibility_code = self.extract_attribute(json_data, 'V', data_type, time_period)
     if self._visibility_code is not None:
         self._visibility_text = metoffer.VISIBILITY[self._visibility_code]
     self._weather_type_code = self.extract_attribute(json_data, 'W', data_type, time_period)
     if self._weather_type_code is not None:
         self._weather_type_text = metoffer.WEATHER_CODES[int(self._weather_type_code)]
示例#4
0
    def parse_json(self, json_data, data_type, time_period):
        self._time = self.extract_attribute(json_data, '$', data_type,
                                            time_period)
        self._temperature_feels_like = self.extract_attribute(
            json_data, 'F', data_type, time_period)
        self._wind_gust = self.extract_attribute(json_data, 'G', data_type,
                                                 time_period)
        self._screen_relative_humidity = self.extract_attribute(
            json_data, 'H', data_type, time_period)
        self._temperature = self.extract_attribute(json_data, 'T', data_type,
                                                   time_period)
        self._visibility_code = self.extract_attribute(json_data, 'V',
                                                       data_type, time_period)
        if self._visibility_code is not None:
            self._visibility_text = metoffer.VISIBILITY[self._visibility_code]
        self._wind_direction = self.extract_attribute(json_data, 'D',
                                                      data_type, time_period)
        if self._wind_direction is not None:
            self._wind_direction_full = self.direction_to_full_text(
                self._wind_direction)
        self._wind_speed = self.extract_attribute(json_data, 'S', data_type,
                                                  time_period)
        self._uv_index_max = self.extract_attribute(json_data, 'U', data_type,
                                                    time_period)
        if self._uv_index_max is not None:
            self._uv_guidance = metoffer.guidance_UV(int(self._uv_index_max))
        self._weather_type_code = self.extract_attribute(
            json_data, 'W', data_type, time_period)
        if self._weather_type_code is not None:
            self._weather_type_text = metoffer.WEATHER_CODES[int(
                self._weather_type_code)]
            self._weather_type_text = self._weather_type_text.replace(
                "(day)", "")
            self._weather_type_text = self._weather_type_text.replace(
                "(night)", "")

        self._precipitation_probability = self.extract_attribute(
            json_data, 'Pp', data_type, time_period)
示例#5
0
    def parse_json(self, json_data, data_type, time_period):
        self._time = self.extract_attribute(json_data, '$', data_type, time_period)
        self._temperature_feels_like = self.extract_attribute(json_data, 'F', data_type, time_period)
        self._wind_gust = self.extract_attribute(json_data, 'G', data_type, time_period)
        self._screen_relative_humidity = self.extract_attribute(json_data, 'H', data_type, time_period)
        self._temperature = self.extract_attribute(json_data, 'T', data_type, time_period)
        self._visibility_code = self.extract_attribute(json_data, 'V', data_type, time_period)
        if self._visibility_code is not None:
            self._visibility_text = metoffer.VISIBILITY[self._visibility_code]
        self._wind_direction = self.extract_attribute(json_data, 'D', data_type, time_period)
        if self._wind_direction is not None:
            self._wind_direction_full = self.direction_to_full_text(self._wind_direction)
        self._wind_speed = self.extract_attribute(json_data, 'S', data_type, time_period)
        self._uv_index_max = self.extract_attribute(json_data, 'U', data_type, time_period)
        if self._uv_index_max is not None:
            self._uv_guidance = metoffer.guidance_UV(int(self._uv_index_max))
        self._weather_type_code = self.extract_attribute(json_data, 'W', data_type, time_period)
        if self._weather_type_code is not None:
            self._weather_type_text = metoffer.WEATHER_CODES[int(self._weather_type_code)]
            self._weather_type_text = self._weather_type_text.replace("(day)", "")
            self._weather_type_text = self._weather_type_text.replace("(night)", "")

        self._precipitation_probability = self.extract_attribute(json_data, 'Pp', data_type, time_period)
    def ReadData(self):
        # Get sun rise and set times etc
        oAstral = Astral()  # Create object
        sCity = oAstral['London']
        #sun = sCity.sun(date=datetime.date(2017, 5, 11), local=True)
        sun = sCity.sun(date=datetime.datetime.now(), local=True)
        self.dDawn = float(
            (str(sun['dawn'])[11:16]).replace(':', '.')
        )  # Get dawn time, also only give charters 11 to 16. Replace : with . and convert to float.
        self.dSunRise = float((str(sun['sunrise'])[11:16]).replace(':', '.'))
        self.dNoon = float((str(sun['noon'])[11:16]).replace(':', '.'))
        self.dSunSet = float((str(sun['sunset'])[11:16]).replace(':', '.'))
        self.dDusk = float((str(sun['dusk'])[11:16]).replace(':', '.'))
        if bDebugPrint == 1:
            print('Sun times for: ' + str(sCity))
            print('Latitude: %.02f; Longitude: %.02f\n' %
                  (sCity.latitude, sCity.longitude))
            print('Dawn: ' + str(self.dDawn))
            print('Sunrise: ' + str(self.dSunRise))
            print('Noon: ' + str(self.dNoon))
            print('Sunset: ' + str(self.dSunSet))
            print('Dusk: ' + str(self.dDusk))
            print('')

        # Decide what time step to use
        if self.sMeasurementType == 'nearest_loc_obs':
            self.nTimeStep = len(
                self.oWeatherReport.data
            ) - 1  # Last item is the latest observation data i.e. current time (list starts at 0 not 1 so need to subtract 1). I think each increment is 1 hour for observation data
        if self.sMeasurementType == 'nearest_loc_forecast':
            self.nTimeStep = 2  # Each data item increments the time by 3 hours for forecast data. 2 seems to represent close to real time forecast.
        self.dicWeatherData = self.oWeatherReport.data[self.nTimeStep]

        # Items common to both Measurement Types
        self.sTimeStamp = self.dicWeatherData['timestamp'][0]
        self.dElevation_m = self.oWeatherReport.elevation
        self.dTemperature_C = self.dicWeatherData['Temperature'][0]
        self.dHumidity_P = self.dicWeatherData['Screen Relative Humidity'][0]
        self.dWindSpeed_mph = self.dicWeatherData['Wind Speed'][0]
        self.sWindDirection = self.dicWeatherData['Wind Direction'][0]
        self.dWindDirection = CompassToDegrees(
            self.sWindDirection)  # Convert wind direction to degrees
        self.nWeatherTypeID = self.dicWeatherData['Weather Type'][0]
        self.sWeatherType = metoffer.WEATHER_CODES[
            self.
            nWeatherTypeID]  # Lookup the type of weather from the metoffer module based on the weather ID.
        self.sWeatherType, sSeparator, sEndText = self.sWeatherType.partition(
            '('
        )  # Remove the last bit of text which is in brackets. eg (night)

        if self.sMeasurementType == 'nearest_loc_obs':  # Items unique to nearest_loc_obs
            self.sNearestLocation = self.oWeatherReport.name
            self.dNearestLatitude = self.oWeatherReport.lat
            self.dNearestLongitude = self.oWeatherReport.lon
            self.dDistanceToStation_km = DistanceBetweenPoints(
                self.dLatitude, self.dLongitude, self.dNearestLatitude,
                self.dNearestLongitude
            )  # Function to give distance between two points
            self.dDewPoint_C = self.dicWeatherData['Dew Point'][0]
            self.dPressure_hPa = self.dicWeatherData['Pressure'][0]
            self.sPressureTendency = self.dicWeatherData['Pressure Tendency'][
                0]
            if self.sPressureTendency == 'R':
                self.sPressureTendency = 'Rise -> Better Weather'
            if self.sPressureTendency == 'F':
                self.sPressureTendency = 'Fall -> Worst Weather'
            self.dVisibility_m = self.dicWeatherData['Visibility'][
                0]  # For some reason the visiility is returned as a number rather than an ID. I think this is a Met Office error.

        if self.sMeasurementType == 'nearest_loc_forecast':  # Items unique to nearest_loc_forecast
            self.dFeelTemperature_C = self.dicWeatherData[
                'Feels Like Temperature'][0]
            self.dWindGust_mph = self.dicWeatherData['Wind Gust'][0]
            self.dPrecipitationProbability_P = self.dicWeatherData[
                'Precipitation Probability'][0]
            self.nMaxUVIndex = self.dicWeatherData['Max UV Index'][0]
            self.sUVGuideance = metoffer.guidance_UV(
                self.nMaxUVIndex
            )  # Function to return the Met Office guideance on UV exposure
            self.dVisibilityID = self.dicWeatherData['Visibility'][0]
            self.sVisibility = metoffer.VISIBILITY[
                self.
                dVisibilityID]  # Function to return visibility description