Esempio n. 1
0
    def check(self):
        logger = logging.getLogger(__name__)

        logger.debug('Starting check...')
        download, upload = Monitor.speedtest()
        sdl, sul = ps(download), ps(upload)
        logger.info('Current speed: %s/%s', sdl, sul)

        if self.speed_is_low(download, upload):
            # updating count before the next branch here ensures only one tweet
            # will be sent in a "bad speed window", that is, it will only tweet
            # again once your speed goes above minimum expected values
            self.warning_count += 1

            logger.warning('Detected bandwidth under minimal expected!')

            # wait 10 minutes to issue a tweet and only tweet once every 3 hours
            if self.time_to_tweet():
                logger.warning('Bandwidth low for too long, sending tweet.')
                tweet = self.message.format(sdl, sul, download=sdl, upload=sul)
                logger.debug('Formatted tweet: %s', tweet)

                # actually send the tweet
                self.twitter.statuses.update(status=tweet)
                self.last_tweet = time.time()

        else:
            logger.debug('Everything working as expected.')
            self.warning_count = 0

        logger.debug('Finished check.')
Esempio n. 2
0
    def __init__(self, expected, auth, message, ratio=0.4, threshold=5):
        self.expected = Bandwidth(download=expected.download * ratio,
                upload=expected.upload * ratio)
        self.message = message
        self.twitter = twitter.Twitter(auth=auth)
        self.warning_count = 0
        self.threshold = threshold
        self.last_tweet = 0

        logger = logging.getLogger(__name__)
        logger.info('Minimum expected speed: %s/%s' % (
            ps(self.expected.download),
            ps(self.expected.upload),))