Code Duplication    Length = 37-37 lines in 3 locations

excelexporters/virtualmetercost.py 1 location

@@ 23-59 (lines=37) @@
20
# Step 3: Encode the excelexporters file to Base64
21
####################################################################################################################
22
23
def export(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
24
    ####################################################################################################################
25
    # Step 1: Validate the report data
26
    ####################################################################################################################
27
    if report is None:
28
        return None
29
30
    if "reporting_period" not in report.keys() or \
31
            "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0:
32
        return None
33
    ####################################################################################################################
34
    # Step 2: Generate excel file from the report data
35
    ####################################################################################################################
36
    filename = generate_excel(report,
37
                              name,
38
                              reporting_start_datetime_local,
39
                              reporting_end_datetime_local,
40
                              period_type)
41
    ####################################################################################################################
42
    # Step 3: Encode the excel file to Base64
43
    ####################################################################################################################
44
    try:
45
        with open(filename, 'rb') as binary_file:
46
            binary_file_data = binary_file.read()
47
    except IOError as ex:
48
        pass
49
50
    # Base64 encode the bytes
51
    base64_encoded_data = base64.b64encode(binary_file_data)
52
    # get the Base64 encoded data using human-readable characters.
53
    base64_message = base64_encoded_data.decode('utf-8')
54
    # delete the file from server
55
    try:
56
        os.remove(filename)
57
    except NotImplementedError as ex:
58
        pass
59
    return base64_message
60
61
62
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/offlinemetercost.py 1 location

@@ 23-59 (lines=37) @@
20
# Step 3: Encode the excelexporters file to Base64
21
####################################################################################################################
22
23
def export(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
24
    ####################################################################################################################
25
    # Step 1: Validate the report data
26
    ####################################################################################################################
27
    if report is None:
28
        return None
29
30
    if "reporting_period" not in report.keys() or \
31
            "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0:
32
        return None
33
    ####################################################################################################################
34
    # Step 2: Generate excel file from the report data
35
    ####################################################################################################################
36
    filename = generate_excel(report,
37
                              name,
38
                              reporting_start_datetime_local,
39
                              reporting_end_datetime_local,
40
                              period_type)
41
    ####################################################################################################################
42
    # Step 3: Encode the excel file to Base64
43
    ####################################################################################################################
44
    try:
45
        with open(filename, 'rb') as binary_file:
46
            binary_file_data = binary_file.read()
47
    except IOError as ex:
48
        pass
49
50
    # Base64 encode the bytes
51
    base64_encoded_data = base64.b64encode(binary_file_data)
52
    # get the Base64 encoded data using human-readable characters.
53
    base64_message = base64_encoded_data.decode('utf-8')
54
    # delete the file from server
55
    try:
56
        os.remove(filename)
57
    except NotImplementedError as ex:
58
        pass
59
    return base64_message
60
61
62
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):

excelexporters/metercost.py 1 location

@@ 23-59 (lines=37) @@
20
# Step 3: Encode the excelexporters file to Base64
21
####################################################################################################################
22
23
def export(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):
24
    ####################################################################################################################
25
    # Step 1: Validate the report data
26
    ####################################################################################################################
27
    if report is None:
28
        return None
29
30
    if "reporting_period" not in report.keys() or \
31
            "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0:
32
        return None
33
    ####################################################################################################################
34
    # Step 2: Generate excel file from the report data
35
    ####################################################################################################################
36
    filename = generate_excel(report,
37
                              name,
38
                              reporting_start_datetime_local,
39
                              reporting_end_datetime_local,
40
                              period_type)
41
    ####################################################################################################################
42
    # Step 3: Encode the excel file to Base64
43
    ####################################################################################################################
44
    try:
45
        with open(filename, 'rb') as binary_file:
46
            binary_file_data = binary_file.read()
47
    except IOError as ex:
48
        pass
49
50
    # Base64 encode the bytes
51
    base64_encoded_data = base64.b64encode(binary_file_data)
52
    # get the Base64 encoded data using human-readable characters.
53
    base64_message = base64_encoded_data.decode('utf-8')
54
    # delete the file from server
55
    try:
56
        os.remove(filename)
57
    except NotImplementedError as ex:
58
        pass
59
    return base64_message
60
61
62
def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type):