예제 #1
0
    def testRetrieveHourlyForecast_hourCountBelowThreshold_throwsException(
            self):
        with self.assertRaises(ValueError) as cm:
            EnvCanada.retrieveHourlyForecast('Ottawa', 0)

        self.assertEqual("hourCount must be between 1 and 24.",
                         cm.exception.args[0])
예제 #2
0
def alertIfRainInShortermForecast(event):
    forecasts = EnvCanada.retrieveHourlyForecast('Ottawa', 12)
    rainPeriods = [f for f in forecasts if \
                 'High' == f.getPrecipationProbability() or \
                 'Medium' == f.getPrecipationProbability()]
    if len(rainPeriods) > 0:
        if len(rainPeriods) == 1:
            subject = u"Possible precipation at {}".format(
                rainPeriods[0].getUserFriendlyForecastTime())
        else:
            subject = u"Possible precipation from {} to {}".format(
                rainPeriods[0].getUserFriendlyForecastTime(),
                rainPeriods[-1].getUserFriendlyForecastTime())

        body = u'Forecasts:\n'
        body += u"{:5} {:7} {:25} {:6} {:6}\n".format('Hour: ', 'Celsius',
                                                      'Condition', 'Prob.',
                                                      'Wind')
        for f in forecasts:
            body += unicode(f) + '\n'

        alert = Alert.createInfoAlert(subject, body)
        result = AlertManager.processAlert(alert, zm)
        if not result:
            PE.logInfo('Failed to send rain alert')
예제 #3
0
    def testRetrieveHourlyForecast_validCity_returnsForecast(self):
        forecasts = EnvCanada.retrieveHourlyForecast('Ottawa')
        self.assertTrue(len(forecasts) > 0)

        for forecast in forecasts:
            self.assertTrue(forecast.getForecastTime() >= 0)
            self.assertTrue(len(forecast.getCondition()) > 0)
            self.assertTrue(len(forecast.getPrecipationProbability()) > 0)
예제 #4
0
    def testRetrieveHourlyForecast_validUrl_returnsForecast(self):
        forecasts = EnvCanada.retrieveHourlyForecast(
            'https://www.weather.gc.ca/forecast/hourly/on-118_metric_e.html',
            24)
        self.assertEqual(24, len(forecasts))

        for forecast in forecasts:
            self.assertTrue(forecast.getForecastTime() >= 0)
            self.assertTrue(len(forecast.getCondition()) > 0)
            self.assertTrue(len(forecast.getPrecipationProbability()) > 0)
def getMorningAnnouncement():
    message = u'Good morning. It is {} degree currently; the weather ' \
        'condition is {}. Forecasted temperature range is between {} and {} ' \
        'degrees.'.format(
            items['VT_Weather_Temperature'].intValue(),
            items['VT_Weather_Condition'].toString(),
            items['VT_Weather_ForecastTempMin'].intValue(),
            items['VT_Weather_ForecastTempMax'].intValue())

    forecasts = EnvCanada.retrieveHourlyForecast('Ottawa', 12)
    rainPeriods = [f for f in forecasts if \
                 'High' == f.getPrecipationProbability() or \
                 'Medium' == f.getPrecipationProbability()]
    if len(rainPeriods) > 0:
        if len(rainPeriods) == 1:
            message += u" There will be precipation at {}.".format(
                rainPeriods[0].getUserFriendlyForecastTime())
        else:
            message += u" There will be precipation from {} to {}.".format(
                rainPeriods[0].getUserFriendlyForecastTime(),
                rainPeriods[-1].getUserFriendlyForecastTime())

    return message
예제 #6
0
    def testRetrieveHourlyForecast_invalidCity_throwsException(self):
        with self.assertRaises(ValueError) as cm:
            EnvCanada.retrieveHourlyForecast('blah')

        self.assertEqual("Can't map city name to URL for blah",
                         cm.exception.args[0])