def test_run(self) -> None: """tests the function that Logs data """ appConfig = getConfig() appLogger = initAppLogger(appConfig) appLogger.info("test logging", extra={"ctx": "testing"}) self.assertTrue(True)
def test_run(self) -> None: """tests the function that sends sms """ appConfig = getConfig() # print(appConfig) smsUsername = appConfig['smsUsername'] smsPass = appConfig['smsPassword'] api = SmsApi(smsUsername, smsPass) resp: str = api.SendSms('8369949816', 'hi from python') self.assertTrue(resp.startswith('OK'))
def test_run(self) -> None: """tests the function that sends sms """ appConfig = getConfig() # print(appConfig) emailUsername = appConfig['emailUsername'] emailPass = appConfig['emailPassword'] emailAddress = appConfig['emailAddress'] emailHost = appConfig['emailHost'] emailApi = EmailSender( emailAddress, emailUsername, emailPass, emailHost) emailApi.sendEmail( ['*****@*****.**'], "Testing email sender in python", 'Hello from python script!') self.assertTrue(1 == 1)
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
def setUp(self): self.appConfig = getConfig()
''' This is the web server that acts as a service that creates outages raw data ''' from src.config.appConfig import getConfig from flask import Flask, request, jsonify, render_template from src.services.tempHumApiFetcher import TempHumApiFetcher import datetime as dt from waitress import serve app = Flask(__name__) # get application config appConfig = getConfig() # Set the secret key to some random bytes app.secret_key = appConfig['flaskSecret'] tokenUrl: str = appConfig['tokenUrl'] apiBaseUrl: str = appConfig['apiBaseUrl'] clientId: str = appConfig['clientId'] clientSecret: str = appConfig['clientSecret'] tempHumFetcher = TempHumApiFetcher(tokenUrl, apiBaseUrl, clientId, clientSecret) @app.route('/api/<measId>/<startTime>/<endTime>') def deviceDataApi(measId: str, startTime: str, endTime: str): startDt = dt.datetime.strptime(startTime, '%Y-%m-%d-%H-%M-%S') endDt = dt.datetime.strptime(endTime, '%Y-%m-%d-%H-%M-%S') resData = tempHumFetcher.fetchData(measId, startDt, endDt) return jsonify(resData)
# 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') endDate = endDate.replace(hour=23, minute=59, second=59) startDateReportString = dt.datetime.strftime(startDate, '%d-%b-%Y') endDateReportString = dt.datetime.strftime(endDate, '%d-%b-%Y') weekNum = getWeekNumOfFinYr(startDate) finYr = getFinYearForDt(startDate) finYrStr = '{0}-{1}'.format(finYr, (finYr + 1) % 100) # get app db connection string from config file appConfig: IAppConfig = getConfig() appDbConStr: str = appConfig['appDbConStr'] # create context for weekly reoport # initialise report context reportContext: IReportCxt = { 'startDt': startDateReportString, 'endDt': endDateReportString, 'wkNum': weekNum, 'finYr': finYrStr, 'genOtgs': [], 'transOtgs': [], 'longTimeOtgs': [], 'freqProfRows': [], 'weeklyFdi': -1, 'wideViols': [],
def setUp(self): appConfig = getConfig() self.appDbConStr = appConfig['appDbConStr']
configPath = 'config.xlsx' configSheet = 'config' pntsSheet = 'pnts' parser.add_argument('--configPath', help="Enter path for config file", default=configPath) parser.add_argument('--configSheet', help="Enter path for config file", default=configSheet) # get the dictionary of command line inputs entered by the user args = parser.parse_args() # access each command line input from the dictionary configPath = args.configPath configSheet = args.configSheet appConfig = getConfig(configFilename=configPath, sheetName=configSheet) pnts = getFetchPnts(configFilename=configPath, sheetName=pntsSheet) startVarTime = VariableTime( appConfig["varStartYears"], appConfig["varStartMonths"], appConfig["varStartDays"], appConfig["varStartHours"], appConfig["varStartMinutes"], appConfig["varStartSeconds"], appConfig["absoluteStartTime"]) endVarTime = VariableTime(appConfig["varEndYears"], appConfig["varEndMonths"], appConfig["varEndDays"], appConfig["varEndHours"], appConfig["varEndMinutes"], appConfig["varEndSeconds"], appConfig["absoluteEndTime"]) startTime = startVarTime.getTimeObj() endTime = endVarTime.getTimeObj()
# %% from src.fetchers.dayAngleSummaryFetcher import fetchAngleSummaryForDate from src.config.appConfig import getConfig import datetime as dt # %% appConf = getConfig() # %% targetDt = dt.datetime(2020, 8, 9) data = fetchAngleSummaryForDate(appConf['anglFolderPath'], targetDt) # %%