def test_getFirstMondayBeforeDate(self) -> None:
     """tests the function that gets the first Monday before a date
     """
     inpDt = dt.datetime(2020, 10, 1)
     mondayDt = getMondayBeforeDt(inpDt)
     self.assertTrue((mondayDt -
                      dt.datetime(2020, 9, 28)) == dt.timedelta(days=0))
def create_weekly_report():
    # get start and end dates from post request body
    reqData = request.get_json()
    try:
        startDate = dt.datetime.strptime(reqData['startDate'], '%Y-%m-%d')
        endDate = dt.datetime.strptime(reqData['endDate'], '%Y-%m-%d')
    except Exception as ex:
        return jsonify({
            'message':
            'Unable to parse start and end dates of this request body'
        }), 400
    # get app db connection string from config file
    appConfig: IAppConfig = getConfig()
    appDbConStr: str = appConfig['appDbConStr']
    dumpFolder: str = appConfig['dumpFolder']
    # generate report word file
    tmplPath: str = "assets/weekly_report_template.docx"
    # create weekly report
    wklyRprtGntr = WeeklyReportGenerator(appDbConStr)
    # use while loop to create multiple reports at once
    currDt: dt.datetime = startDate
    while currDt <= endDate:
        currStartDt = getMondayBeforeDt(currDt)
        currEndDt = getSundayAfterDt(currStartDt)
        isWeeklyReportGenerationSuccess: bool = wklyRprtGntr.generateWeeklyReport(
            currStartDt, currEndDt, tmplPath, dumpFolder)
        currDt = currEndDt + dt.timedelta(days=1)
    if isWeeklyReportGenerationSuccess:
        return jsonify({
            'message': 'weekly report generation successful!!!',
            'startDate': startDate,
            'endDate': endDate
        })
    else:
        return jsonify({'message':
                        'weekly report generation was not success'}), 500
from src.typeDefs.stationwiseVdiData import IStationwiseVdi
from src.typeDefs.outage import IOutage
from src.typeDefs.iegcViolMsg import IIegcViolMsg
from src.typeDefs.angleViolSummary import IAngleViolSummary
from src.typeDefs.ictConstraint import IIctConstraint
from src.typeDefs.transConstraint import ITransConstraint
from src.typeDefs.hvNodesInfo import IHvNodesInfo
from src.typeDefs.lvNodesInfo import ILvNodesInfo
from src.typeDefs.appConfig import IAppConfig
from src.typeDefs.reportContext import IReportCxt
from typing import List

# get start and end dates from command line
# initialise default command line input values
startDate = dt.datetime.now() - dt.timedelta(days=7)
startDate = getMondayBeforeDt(startDate)
endDate = startDate + dt.timedelta(days=6)

# get an instance of argument parser from argparse module
parser = argparse.ArgumentParser()
# setup arguements
parser.add_argument('--start_date',
                    help="Enter Start date in yyyy-mm-dd format",
                    default=dt.datetime.strftime(startDate, '%Y-%m-%d'))
parser.add_argument('--end_date',
                    help="Enter last date in yyyy-mm-dd format",
                    default=dt.datetime.strftime(endDate, '%Y-%m-%d'))
# get the dictionary of command line inputs entered by the user
args = parser.parse_args()

# access each command line input from the dictionary
import argparse
import datetime as dt
from src.utils.timeUtils import getMondayBeforeDt, getSundayAfterDt
from src.config.appConfig import getConfig
from src.typeDefs.appConfig import IAppConfig
from src.app.weeklyReportGenerator import WeeklyReportGenerator
from src.appLogger import initAppLogger

# get start and end dates from command line
# initialise default command line input values
startDate = dt.datetime.now() - dt.timedelta(days=7)
startDate = getMondayBeforeDt(startDate)
endDate = startDate + dt.timedelta(days=6)

# get an instance of argument parser from argparse module
parser = argparse.ArgumentParser()
# setup arguements
parser.add_argument('--start_date', help="Enter Start date in yyyy-mm-dd format",
                    default=dt.datetime.strftime(startDate, '%Y-%m-%d'))
parser.add_argument('--end_date', help="Enter last date in yyyy-mm-dd format",
                    default=dt.datetime.strftime(endDate, '%Y-%m-%d'))
# get the dictionary of command line inputs entered by the user
args = parser.parse_args()

# access each command line input from the dictionary
startDate = dt.datetime.strptime(args.start_date, '%Y-%m-%d')
endDate = dt.datetime.strptime(args.end_date, '%Y-%m-%d')
# get app config
appConfig: IAppConfig = getConfig()

# initialize logger