示例#1
0
 def convert_from_api(action):
     dt = mygpoutil.iso8601_to_datetime(action.timestamp)
     action_ts = calendar.timegm(dt.timetuple())
     return ReceivedEpisodeAction(action.podcast, action.episode,
                                  action.device, action.action,
                                  action_ts, action.started,
                                  action.position, action.total)
示例#2
0
文件: my.py 项目: xerxes2/gpodder
 def convert_from_api(action):
     dt = mygpoutil.iso8601_to_datetime(action.timestamp)
     since = int(dt.strftime('%s'))
     return ReceivedEpisodeAction(action.podcast, \
             action.episode, action.device, \
             action.action, since, \
             action.started, action.position, action.total)
示例#3
0
文件: my.py 项目: Mortal/gpodder
 def convert_from_api(action):
     dt = mygpoutil.iso8601_to_datetime(action.timestamp)
     action_ts = calendar.timegm(dt.timetuple())
     return ReceivedEpisodeAction(action.podcast, \
             action.episode, action.device, \
             action.action, action_ts, \
             action.started, action.position, action.total)
示例#4
0
文件: my.py 项目: xerxes2/gpodder
 def convert_from_api(action):
     dt = mygpoutil.iso8601_to_datetime(action.timestamp)
     since = int(dt.strftime('%s'))
     return ReceivedEpisodeAction(action.podcast, \
             action.episode, action.device, \
             action.action, since, \
             action.started, action.position, action.total)
示例#5
0
    def __init__(self, podcast, episode, action,
            device=None, timestamp=None,
            started=None, position=None, total=None):
        # Check if the action is valid
        if action not in self.VALID_ACTIONS:
            raise ValueError('Invalid action type "%s" (see VALID_ACTIONS)' % action)

        # Disallow play-only attributes for non-play actions
        if action != 'play':
            if started is not None:
                raise ValueError('Started can only be set for the "play" action')
            elif position is not None:
                raise ValueError('Position can only be set for the "play" action')
            elif total is not None:
                raise ValueError('Total can only be set for the "play" action')

        # Check the format of the timestamp value
        if timestamp is not None:
            if util.iso8601_to_datetime(timestamp) is None:
                raise ValueError('Timestamp has to be in ISO 8601 format but was %s' % timestamp)

        # Check if we have a "position" value if we have started or total
        if position is None and (started is not None or total is not None):
            raise ValueError('Started or total set, but no position given')

        # Check that "started" is a number if it's set
        if started is not None:
            try:
                started = int(started)
            except ValueError:
                raise ValueError('Started must be an integer value (seconds) but was %s' % started)

        # Check that "position" is a number if it's set
        if position is not None:
            try:
                position = int(position)
            except ValueError:
                raise ValueError('Position must be an integer value (seconds) but was %s' % position)

        # Check that "total" is a number if it's set
        if total is not None:
            try:
                total = int(total)
            except ValueError:
                raise ValueError('Total must be an integer value (seconds) but was %s' % total)

        self.podcast = podcast
        self.episode = episode
        self.action = action
        self.device = device
        self.timestamp = timestamp
        self.started = started
        self.position = position
        self.total = total
示例#6
0
    def __init__(self, podcast, episode, action,
            device=None, timestamp=None,
            started=None, position=None, total=None):
        # Check if the action is valid
        if action not in self.VALID_ACTIONS:
            raise ValueError('Invalid action type "%s" (see VALID_ACTIONS)' % action)

        # Disallow play-only attributes for non-play actions
        if action != 'play':
            if started is not None:
                raise ValueError('Started can only be set for the "play" action')
            elif position is not None:
                raise ValueError('Position can only be set for the "play" action')
            elif total is not None:
                raise ValueError('Total can only be set for the "play" action')

        # Check the format of the timestamp value
        if timestamp is not None:
            if util.iso8601_to_datetime(timestamp) is None:
                raise ValueError('Timestamp has to be in ISO 8601 format but was %s' % timestamp)

        # Check if we have a "position" value if we have started or total
        if position is None and (started is not None or total is not None):
            raise ValueError('Started or total set, but no position given')

        # Check that "started" is a number if it's set
        if started is not None:
            try:
                started = int(started)
            except ValueError:
                raise ValueError('Started must be an integer value (seconds) but was %s' % started)

        # Check that "position" is a number if it's set
        if position is not None:
            try:
                position = int(position)
            except ValueError:
                raise ValueError('Position must be an integer value (seconds) but was %s' % position)

        # Check that "total" is a number if it's set
        if total is not None:
            try:
                total = int(total)
            except ValueError:
                raise ValueError('Total must be an integer value (seconds) but was %s' % total)

        self.podcast = podcast
        self.episode = episode
        self.action = action
        self.device = device
        self.timestamp = timestamp
        self.started = started
        self.position = position
        self.total = total