예제 #1
0
    def updateExcel(self, args: dict) -> CommandHandlerResponse:

        if not (self.timeIntervalIsSufficient(Function.updateExcel)):
            return CommandHandlerResponse(
                responseInfo=ResponseInfo.TimeIntervalIsNotSufficient)

        self.updateLastExecutionTime(Function.updateExcel)
        # try:
        #     filePath = args["excelPath"]
        #     diapasonsPath = args["diapasonsPath"]
        #     ...
        # except Some--Exception:
        #     raise InvalidArgumrent Exception
        #         or CommandHandlerResponse

        excelPath = args[Request.filePath]
        diapasonsPath = "../data/diapasonsDad.csv"
        firmsPath = "../data/firms.csv"
        excelManager = ExcelManager(excelPath)

        try:
            diapasons = FileManager.readCSVto2DimensionalList(
                diapasonsPath, " ")
            firms = FileManager.readCSVtoDict(firmsPath, ",")

            FileValidator.checkDataFilesForCorrectness(diapasons, 5,
                                                       diapasonsPath, firms, 2,
                                                       firmsPath)
            excelManager.updateExcel(diapasons, firms)

            return CommandHandlerResponse(
                responseInfo=ResponseInfo.OK,
                successMessage="\nExcel was updated successfully!")

        except FileNotFoundError as e:
            return CommandHandlerResponse(
                responseInfo=ResponseInfo.FileNotFoundException,
                errorsMessage=str(e))

        except InvalidDataFileException as e:
            return CommandHandlerResponse(
                responseInfo=ResponseInfo.InvalidDataFileException,
                errorsMessage=str(e))

        except InvalidLinkException as e:
            return CommandHandlerResponse(
                responseInfo=ResponseInfo.InvalidLinkException,
                successMessage="\nExcel was partially updated.",
                errorsMessage=str(e))
예제 #2
0
from CustomExceptions.InvalidDataFileException import InvalidDataFileException
from CustomExceptions.InvalidLinkException import InvalidLinkException
from src.FileManager import FileManager
from src.ExcelManager import ExcelManager
from src.FileValidator import FileValidator

excelPath = "hello_world.xlsx"
diapasonsPath = "../data/diapasons.csv"
firmsPath = "../data/firms.csv"
excelManager = ExcelManager(excelPath)

diapasons = FileManager.readCSVto2DimensionalList(diapasonsPath, " ")
firms = FileManager.readCSVtoDict(firmsPath, ",")

# for key, value in firms:
#     print("Firms:\n========================\n")
#     print(key, " : ", value)

# for key in firms.keys():
#     print(key, " : ", firms[key])

# print("Firms:\n========================\n", firms)
# print(FileManager.readCSVtoDict(firms, ","))
try:
    FileValidator.checkDataFilesForCorrectness(diapasons, 5, diapasonsPath,
                                               firms, 2, firmsPath)
    print("Data files was loaded successfully.")
except InvalidDataFileException as e:
    print("Exceptions during loading the data files: ", e)

try: