Beispiel #1
0
def main(tomorrow=False, weekly_report=False):
    if not TESTING and platform.system() == 'Windows':
        raise RuntimeError('Only linux')

    logger.debug('Starting app, tomorrow=%r, weekly_report=%r', tomorrow,
                 weekly_report)
    data = from_google_spreadsheets()

    logger.debug('Data=%r', data)

    if weekly_report:
        try:
            report = gen_weekly_report(data)
        except RuntimeError:
            return False
        destinations = list(ALIAS_TO_MAIL.values())
        return send_email(destinations, 'Informe Semanal', report)

    daycode = get_daycode(tomorrow=tomorrow)

    logger.debug('Daycode=%r', daycode)

    if daycode not in data:
        logger.critical('Daycode (%r) not in data', daycode)

        month, day = split_daycode(daycode)

        datetime_ = datetime.datetime(2019, month, day)
        logger.debug('Day=%r, month=%r, weekday=%r', day, month,
                     datetime_.weekday())

        if not is_class(datetime_):
            logger.debug('Identified as weekend')
            return True

        return send_email(ADMIN_EMAIL, 'ERROR',
                          f'{daycode!r} is not defined in the database')

    if data[daycode] not in ALIAS_TO_MAIL:
        logger.debug('Data is not a known alias, broadcasting')
        destinations = list(ALIAS_TO_MAIL.values())
        motive = data[daycode]
    else:
        destinations = ALIAS_TO_MAIL[data[daycode]]
        logger.debug('Found alias: %r', destinations)
        motive = 'C'

    logger.debug('Motive=%r', motive)

    return send_email(destinations, gen_subject(motive, tomorrow),
                      gen_message(motive, tomorrow))
Beispiel #2
0
    def test_week_25(self, data):
        assert main(weekly_report=True)

        mail = read_email()
        assert mail['to'] == list(ALIAS_TO_MAIL.values())
        assert mail['from'] == FROM_EMAIL

        report = gen_weekly_report(data)

        assert 'Informe Semanal' in mail['data']
        assert 'Informe semanal' in report
        assert 'Chiste del día' in report

        assert 'Lunes' not in report
        assert 'Martes' not in report
        assert 'Miércoles' not in report
        assert 'Jueves' not in report
        assert 'Viernes' in report
        assert 'Sábado' not in report
        assert 'Domingo' not in report
Beispiel #3
0
    def test_gen_weekly_report(self):
        try:
            report = gen_weekly_report()
        except RuntimeError as ex:
            assert 'Empty processed data' in str(ex)
            return

        assert 'Monday' not in report
        assert 'Tuesday' not in report
        assert 'Thursday' not in report
        assert 'Friday' not in report
        assert 'Saturday' not in report
        assert 'Sunday' not in report
        assert 'day' not in report

        assert 'Informe semanal' in report
        assert 'Semana No.' in report
        assert report.count('\n') > 1

        assert 'Chiste del día' in report
Beispiel #4
0
    def test_week_26(self, data):
        assert not main(weekly_report=True)
        assert not os.path.isfile(SMTP_PATH)

        with pytest.raises(RuntimeError, match='Empty processed data'):
            gen_weekly_report(data)