Ejemplo n.º 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))
Ejemplo n.º 2
0
    def test_main_2019_06_21(self, data):
        assert main()

        today = get_daycode()
        assert today in data
        assert data[today] == 'D'
        assert data[today] not in ALIAS_TO_MAIL

        mail_data = read_email()
        assert mail_data['to'] == list(ALIAS_TO_MAIL.values())
        assert mail_data['from'] == FROM_EMAIL
        assert 'hoy' in mail_data['data']
        assert isinstance(mail_data, dict)
Ejemplo n.º 3
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