import logging
import time
from datetime import datetime
from lt_analytics.models import generate_today_reports

logger = logging.getLogger("edx.scripts.analytics_generate_reports")
log_handler = logging.handlers.TimedRotatingFileHandler('/edx/var/log/lms/analytics.log',
                                                        when='W0',
                                                        backupCount=5,
                                                        encoding='utf-8')
log_formatter = logging.Formatter('%(asctime)s %(levelname)s  - %(message)s')
log_formatter.converter = time.gmtime
log_handler.setFormatter(log_formatter)
logger.addHandler(log_handler)

logger.info("Starting to generate today's reports...")
start_time = datetime.now()
generate_today_reports()
logger.info("Finished after {}".format(datetime.now() - start_time))
