How to use the aniso8601.parse_duration function in aniso8601

To help you get started, we’ve selected a few aniso8601 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mediadrop / mediadrop / mediadrop / lib / services / youtube.py View on Github external
# LATER: add debug logging for youtube response
        if video_result == False:
            return Result(
                False,
                meta_info=None,
                message=video_result.message
            )
        elif len(video_result) == 0:
            return Result(
                False,
                meta_info=None,
                message=_('Invalid YouTube URL. This video does not exist or is private and can not be embedded.')
            )
        video_details = video_result[0]
        iso8601_duration = video_details['contentDetails']['duration']
        duration = aniso8601.parse_duration(iso8601_duration)
        snippet = video_details['snippet']
        best_thumbnail = self._find_biggest_thumbnail(snippet['thumbnails'])
        meta_info = {
            'unique_id': video_details['id'],
            'duration': timedelta_to_seconds(duration),
            'display_name': snippet['title'],
            'description': snippet['description'],
            'thumbnail': {
                'width': best_thumbnail['width'],
                'height': best_thumbnail['height'],
                'url': best_thumbnail['url'],
            },
            'type': VIDEO,
        }
        return Result(True, meta_info=meta_info, message=None)
github RusticiSoftware / TinCanPython / tincan / conversions / iso8601.py View on Github external
If a number is provided, it will be interpreted as the number of
    seconds.

    If a `dict` is provided, does `datetime.timedelta(**value)`.

    :param value: something to convert
    :type value: str | unicode | float | int | datetime.timedelta | dict
    :return: the value after conversion
    :rtype: datetime.timedelta

    """

    if isinstance(value, basestring):
        try:
            return aniso8601.parse_duration(value)
        except Exception as e:
            msg = (
                "Conversion to datetime.timedelta failed. Could not "
                "parse the given string as an ISO 8601 duration: "
                "%s\n\n"
                "%s" %
                (
                    repr(value),
                    e.message,
                )
            )
            raise ValueError(msg)

    try:
        if isinstance(value, datetime.timedelta):
            return value
github johnwheeler / flask-ask / flask_ask / convert.py View on Github external
def to_timedelta(amazon_duration):
    return aniso8601.parse_duration(amazon_duration)
github tendrilinc / marathon-autoscaler / lib / marathon_autoscaler / history_manager.py View on Github external
def get_timedelta(self, iso8601_time_duration_string):
        """ A facade method for the iso8601.parse_duration method that reads a string,
        containing an iso8601 time duration value, and returns a datetime.timedelta object.
        :param iso8601_time_duration_string: a string containing an iso8601 time duration.
        :return: datetime.timedelta
        """
        time_delta = None
        try:
            time_delta = parse_duration(iso8601_time_duration_string)
        except Exception as ex:
            self.logger.error("Time Duration Unparseable: {td}".format(td=iso8601_time_duration_string))
            self.logger.error(ex)
        finally:
            return time_delta or timedelta(seconds=0)