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