(self, episodes)
return interval
calculates the avg interval between new episodes
calculates the avg interval between new episodes
calculates the avg interval between new episodes
def get_update_interval(self, episodes):
        """calculates the avg interval between new episodes"""

        count = episodes.count()
        if not count:
            logger.info(
                "no episodes, using default interval of %dh", DEFAULT_UPDATE_INTERVAL
            )
            return DEFAULT_UPDATE_INTERVAL

        earliest = episodes.first()
        now = datetime.utcnow()

        timespan_s = (now - earliest.released).total_seconds()
        timespan_h = timespan_s / 60 / 60

        interval = int(timespan_h / count)
        logger.info(
            "%d episodes in %d days => %dh interval", count, timespan_h / 24, interval
        )

        # place interval between {MIN,MAX}_UPDATE_INTERVAL
        interval = max(interval, MIN_UPDATE_INTERVAL)
        interval = min(interval, MAX_UPDATE_INTERVAL)

        return interval
def get_update_interval ( self , episodes ) : count = episodes . count ( ) if not count : logger . info ( "no episodes, using default interval of %dh" , DEFAULT_UPDATE_INTERVAL ) return DEFAULT_UPDATE_INTERVAL earliest = episodes . first ( ) now = datetime . utcnow ( ) timespan_s = ( now - earliest . released ) . total_seconds ( ) timespan_h = timespan_s / 60 / 60 interval = int ( timespan_h / count ) logger . info ( "%d episodes in %d days => %dh interval" , count , timespan_h / 24 , interval ) # place interval between {MIN,MAX}_UPDATE_INTERVAL interval = max ( interval , MIN_UPDATE_INTERVAL ) interval = min ( interval , MAX_UPDATE_INTERVAL ) return interval