示例#1
0
 def __init__(self, id, created_at, updated_at, external_id, name,
              lon, lat, alt, rank):
     assert id is not None
     assert external_id is not None
     assert lon is not None
     assert lat is not None
     if lon < -180.0 or lon > 180.0:
         raise ValueError("'lon' value must be between -180 and 180")
     self._lon = float(lon)
     if lat < -90.0 or lat > 90.0:
         raise ValueError("'lat' value must be between -90 and 90")
     if alt is not None:
         if alt < 0.0:
             raise ValueError("'alt' value must not be negative")
     self.id = id
     self.created_at = created_at
     if self.created_at is not None:
         padded_created_at = self._format_micros(created_at)
         t = dt.strptime(padded_created_at,
                         '%Y-%m-%dT%H:%M:%S.%fZ').replace(
                             tzinfo=timeformatutils.UTC())
         self.created_at = timeformatutils.timeformat(t, 'unix')
     self.updated_at = updated_at
     if self.updated_at is not None:
         padded_updated_at = self._format_micros(updated_at)
         t = dt.strptime(padded_updated_at,
                         '%Y-%m-%dT%H:%M:%S.%fZ').replace(
                             tzinfo=timeformatutils.UTC())
         self.updated_at = timeformatutils.timeformat(t, 'unix')
     self.external_id = external_id
     self.name = name
     self.lon = lon
     self.lat = lat
     self.alt = alt
     self.rank = rank
示例#2
0
 def to_entity(self):
     """
     Generates an Ozone object out of the current model
     :return: a pyowm.webapi25.ozone.Ozone instance
     """
     return OzoneEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location), self.interval, self.du_value,
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#3
0
 def to_entity(self):
     """
     Generates a UVIndex object out of the current model
     :return: a pyowm.webapi25.uvindex.UVIndex instance
     """
     return UVIndexEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location), self.interval, self.value,
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#4
0
 def to_entity(self):
     """
     Generates a COIndex object out of the current model
     :return: a pyowm.webapi25.coindex.COIndex instance
     """
     return COIndexEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location), self.interval,
         json.loads(self.co_samples),
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#5
0
 def to_entity(self):
     """
     Generates an Ozone object out of the current model
     :return: a pyowm.webapi25.ozone.Ozone instance
     """
     return OzoneEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location),
         self.interval,
         self.du_value,
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#6
0
 def to_entity(self):
     """
     Generates a UVIndex object out of the current model
     :return: a pyowm.webapi25.uvindex.UVIndex instance
     """
     return UVIndexEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location),
         self.interval,
         self.value,
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#7
0
 def to_entity(self):
     """
     Generates a COIndex object out of the current model
     :return: a pyowm.webapi25.coindex.COIndex instance
     """
     return COIndexEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         Location.to_entity(self.location),
         self.interval,
         json.loads(self.co_samples),
         timeformatutils.timeformat(self.reception_time, 'unix'))
示例#8
0
 def to_entity(self):
     """
     Generates a Weather object out of the current model
     :return: a pyowm.webapi25.weather.Weather instance
     """
     return WeatherEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         timeformatutils.timeformat(self.sunset_time, 'unix'),
         timeformatutils.timeformat(self.sunrise_time, 'unix'), self.clouds,
         json.loads(self.rain), json.loads(self.snow),
         json.loads(self.wind), self.humidity, json.loads(self.pressure),
         json.loads(self.temperature), self.status, self.detailed_status,
         self.weather_code, self.weather_icon_name,
         self.visibility_distance, self.dewpoint, self.humidex,
         self.heat_index)
示例#9
0
 def test_timeformat(self):
     unixtime = 1378459200
     iso = "2013-09-06 09:20:00+00"
     date = datetime(2013, 9, 6, 9, 20, 0)
     self.assertEqual(unixtime, timeformatutils.timeformat(unixtime, "unix"))
     self.assertEqual(iso, timeformatutils.timeformat(unixtime, "iso"))
     self.assertEqual(date, timeformatutils.timeformat(unixtime, "date"))
     self.assertEqual(unixtime, timeformatutils.timeformat(iso, "unix"))
     self.assertEqual(iso, timeformatutils.timeformat(iso, "iso"))
     self.assertEqual(date, timeformatutils.timeformat(iso, "date"))
     self.assertEqual(unixtime, timeformatutils.timeformat(date, "unix"))
     self.assertEqual(iso, timeformatutils.timeformat(date, "iso"))
     self.assertEqual(date, timeformatutils.timeformat(date, "date"))
示例#10
0
 def to_entity(self):
     """
     Generates an Observation object out of the current model
     :return: a pyowm.webapi25.observation.Observation instance
     """
     return ObservationEntity(
         timeformatutils.timeformat(self.reception_time, 'unix'),
         self.location.to_entity(), self.weather.to_entity())
示例#11
0
 def to_entity(self):
     """
     Generates a StationHistory object out of the current model
     :return: a pyowm.webapi25.stationhistory.StationHistory instance
     """
     data = {int(k): v for k, v in json.loads(self.measurements).items()}
     return StationHistoryEntity(
         self.station_id, self.interval,
         timeformatutils.timeformat(self.reception_time, 'unix'), data)
示例#12
0
 def to_entity(self):
     """
     Generates an Observation object out of the current model
     :return: a pyowm.webapi25.observation.Observation instance
     """
     return ObservationEntity(
         timeformatutils.timeformat(self.reception_time, 'unix'),
         self.location.to_entity(),
         self.weather.to_entity())
示例#13
0
 def to_entity(self):
     """
     Generates a Forecast object out of the current model
     :return: a pyowm.webapi25.forecast.Forecast instance
     """
     return ForecastEntity(
         self.interval,
         timeformatutils.timeformat(self.reception_time, 'unix'),
         self.location.to_entity(),
         [Weather.to_entity(w) for w in self.weathers.all()])
示例#14
0
 def to_entity(self):
     """
     Generates a Forecast object out of the current model
     :return: a pyowm.webapi25.forecast.Forecast instance
     """
     return ForecastEntity(
         self.interval,
         timeformatutils.timeformat(self.reception_time, 'unix'),
         self.location.to_entity(),
         [Weather.to_entity(w) for w in self.weathers.all()])
示例#15
0
 def to_entity(self):
     """
     Generates a StationHistory object out of the current model
     :return: a pyowm.webapi25.stationhistory.StationHistory instance
     """
     data = {int(k): v for k, v in json.loads(self.measurements).items()}
     return StationHistoryEntity(
         self.station_id,
         self.interval,
         timeformatutils.timeformat(self.reception_time, 'unix'),
         data)
示例#16
0
文件: imagery.py 项目: csparpa/pyowm
    def acquisition_time(self, timeformat='unix'):
        """Returns the UTC time telling when the image data was acquired by the satellite

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str

        """
        return timeformatutils.timeformat(self._acquisition_time, timeformat)
示例#17
0
    def downloaded_on(self, timeformat='unix'):
        """Returns the UTC time telling when the satellite image was downloaded from the OWM Agro API

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str

        """
        return timeformatutils.timeformat(self._downloaded_on, timeformat)
示例#18
0
    def issued_on(self, timeformat='unix'):
        """Returns the UTC time telling when the query was performed against the OWM Agro API

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str

        """
        return timeformatutils.timeformat(self.query_timestamp, timeformat)
示例#19
0
    def get_reference_time(self, timeformat='unix'):
        """Returns the GMT time telling when the weather was measured

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time or '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00``
        :type timeformat: str
        :returns: an int or a str
        :raises: ValueError when negative values are provided

        """
        return timeformatutils.timeformat(self._reference_time, timeformat)
示例#20
0
    def get_sunrise_time(self, timeformat='unix'):
        """Returns the GMT time of sunrise

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time or '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00``
        :type timeformat: str
        :returns: an int or a str
        :raises: ValueError

        """
        return timeformatutils.timeformat(self._sunrise_time, timeformat)
示例#21
0
文件: imagery.py 项目: csparpa/pyowm
    def downloaded_on(self, timeformat='unix'):
        """Returns the UTC time telling when the satellite image was downloaded from the OWM Agro API

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str

        """
        return timeformatutils.timeformat(self._downloaded_on, timeformat)
示例#22
0
    def get_reception_time(self, timeformat='unix'):
        """Returns the GMT time telling when the meteostation history data was
           received from the OWM web API

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time or '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00``
        :type timeformat: str
        :returns: an int or a str
        :raises: ValueError

        """
        return timeformatutils.timeformat(self._reception_time, timeformat)
示例#23
0
def now(timeformat='date'):
    """
    Returns the current time in the specified timeformat.

    :param timeformat: the target format for the time conversion. May be:
        '*date*' (default - outputs a ``datetime.datetime`` object), '*unix*'
        (outputs a long UNIXtime) or '*iso*' (outputs an ISO8601-formatted
        string with pattern ``YYYY-MM-DD HH:MM:SS+00``)
    :type timeformat: str
    :returns: the current time value
    :raises: ValueError when unknown timeformat switches are provided or
        when negative time values are provided
    """
    return timeformatutils.timeformat(datetime.now(), timeformat)
示例#24
0
文件: coindex.py 项目: csparpa/pyowm
    def get_reference_time(self, timeformat='unix'):
        """
        Returns the GMT time telling when the CO samples have been measured

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str
        :raises: ValueError when negative values are provided

        """
        return timeformatutils.timeformat(self._reference_time, timeformat)
示例#25
0
def now(timeformat='date'):
    """
    Returns the current time in the specified timeformat.

    :param timeformat: the target format for the time conversion. May be:
        '*date*' (default - outputs a ``datetime.datetime`` object), '*unix*'
        (outputs a long UNIXtime) or '*iso*' (outputs an ISO8601-formatted
        string with pattern ``YYYY-MM-DD HH:MM:SS+00``)
    :type timeformat: str
    :returns: the current time value
    :raises: ValueError when unknown timeformat switches are provided or
        when negative time values are provided
    """
    return timeformatutils.timeformat(datetime.now(), timeformat)
示例#26
0
文件: forecast.py 项目: csparpa/pyowm
    def get_reception_time(self, timeformat='unix'):
        """Returns the GMT time telling when the forecast was received
            from the OWM Weather API

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: an int or a str
        :raises: ValueError

        """
        return timeformatutils.timeformat(self._reception_time, timeformat)
示例#27
0
 def to_entity(self):
     """
     Generates a Weather object out of the current model
     :return: a pyowm.webapi25.weather.Weather instance
     """
     return WeatherEntity(
         timeformatutils.timeformat(self.reference_time, 'unix'),
         timeformatutils.timeformat(self.sunset_time, 'unix'),
         timeformatutils.timeformat(self.sunrise_time, 'unix'),
         self.clouds,
         json.loads(self.rain),
         json.loads(self.snow),
         json.loads(self.wind),
         self.humidity,
         json.loads(self.pressure),
         json.loads(self.temperature),
         self.status,
         self.detailed_status,
         self.weather_code,
         self.weather_icon_name,
         self.visibility_distance,
         self.dewpoint,
         self.humidex,
         self.heat_index)
示例#28
0
    def last_update_time(self, timeformat='unix'):
        """Returns the UTC time of the last update on this station's metadata

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time, '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00`` or `date` for
            a ``datetime.datetime`` object
        :type timeformat: str
        :returns: an int or a str or a ``datetime.datetime`` object or None
        :raises: ValueError

        """
        if self.updated_at is None:
            return None
        return timeformatutils.timeformat(self.updated_at, timeformat)
    def creation_time(self, timeformat='unix'):
        """Returns the UTC time of creation of this aggregated measurement

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time, '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00`` or `date` for
            a ``datetime.datetime`` object
        :type timeformat: str
        :returns: an int or a str or a ``datetime.datetime`` object or None
        :raises: ValueError

        """
        if self.timestamp is None:
            return None
        return timeformatutils.timeformat(self.timestamp, timeformat)
示例#30
0
    def when_ends(self, timeformat='unix'):
        """
        Returns the GMT time of the end of the forecast coverage, which is the
        time of the most recent *Weather* item in the forecast

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time or '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00``
        :type timeformat: str
        :returns: a long or a str
        :raises: *ValueError* when invalid time format values are provided

        """
        end_coverage = max([item.get_reference_time() \
                            for item in self._forecast])
        return timeformatutils.timeformat(end_coverage, timeformat)
示例#31
0
    def when_ends(self, timeformat='unix'):
        """
        Returns the GMT time of the end of the forecast coverage, which is the
        time of the most recent *Weather* item in the forecast

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time or '*iso*' for ISO8601-formatted
            string in the format ``YYYY-MM-DD HH:MM:SS+00``
        :type timeformat: str
        :returns: a long or a str
        :raises: *ValueError* when invalid time format values are provided

        """
        end_coverage = max([item.get_reference_time() \
                            for item in self._forecast])
        return timeformatutils.timeformat(end_coverage, timeformat)
示例#32
0
    def when_starts(self, timeformat='unix'):
        """
        Returns the GMT time of the start of the forecast coverage, which is
        the time of the most ancient *Weather* item in the forecast

        :param timeformat: the format for the time value. May be:
            '*unix*' (default) for UNIX time
            '*iso*' for ISO8601-formatted string in the format ``YYYY-MM-DD HH:MM:SS+00``
            '*date* for ``datetime.datetime`` object instance
        :type timeformat: str
        :returns: a long or a str
        :raises: *ValueError* when invalid time format values are provided

        """
        start_coverage = min([item.get_reference_time() \
                              for item in self._forecast])
        return timeformatutils.timeformat(start_coverage, timeformat)