I have the following function in Python-3
def test_late_logs(tabs_data):
current_date = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0)
text = "*** Manual logging ***\n"
text += f"TAB LATE REPORT. Current date is {current_date}\n"
text += "LATE BY".ljust(9) + "LAST SUCCESSFUL RUN".ljust(27) + "ACCEPTABLE LAG".ljust(16) + "TAB".ljust(50) + "IMPACT".ljust(20) + "DESCRIPTION" + "\n"
for tab_name in tabs_data:
tab_data = tabs_data[tab_name]
text += f"{str(tab_data['is_late_by']):<9}{str(tab_data['last_successful_run']):<27}{str(dtab_data['acceptable_lag']):<16}{str(tab_name):<50}{str(tab_data['impact']):<20}{textwrap.TextWrapper(width=175,subsequent_indent=' '*123).fill(text=str(tab_data['description']))} \n"
return text
When I print text from the above code, I get the following
LATE BY LAST SUCCESSFUL RUN ACCEPTABLE LAG TAB IMPACT DESCRIPTION
0:00:00 2022-03-07 10:00:00+00:00 5:00:00 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx impact_high xxxxxxxxxxxxxxxxxxxxxxx
0:00:00 2022-03-07 10:00:00+00:00 5:00:00 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx impact_high xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
0:00:00 2022-03-07 10:00:00+00:00 5:00:00 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx impact_high xxxxxxxxxxxxxxxxxxxx
0:00:00 2022-03-07 10:00:00+00:00 5:00:00 xxxxxxxxxxxxxxxxx impact_medium xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2:00:00 2022-03-07 12:00:00+00:00 0:00:00 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx impact_medium xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I also tried the following code with different values of initial_indent:
text += f"{str(tab_data['is_late_by']):<9}{str(tab_data['last_successful_run']):<27}{str(tab_data['acceptable_lag']):<16}{str(tab_name):<50}{str(tab_data['impact'])}{textwrap.TextWrapper(initial_indent=' '*1,width=175,subsequent_indent=' '*123).fill(text=str(tab_data['description']))} \n"
But, I am unable to format the wrapped text for 'description' to be placed below the title 'DESCRIPTION'. Is this because of some inherent indentation that already exists? Or am I missing something? Any help will be appreciated.
tabs_data is a dictionary as follows:
tabs_data = {
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx': {
'acceptable_lag' : timedelta(hours=5),
'description' : 'xxxxxxxxxxxxxxxxxxxxxxx',
'emails': ['xxxxxxxx@xxxxxxxxxxxx.com'],
'slack_channels': ['#xxxxxxxxxxxxxxx']
},
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx': {
'acceptable_lag': timedelta(hours=5),
'description': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'emails': ['xxxxxxxx@xxxxxxxxxxxx.com'],
'slack_channels': ['#xxxxxxxxxxxxxxx']
},
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx': {
'acceptable_lag' : timedelta(hours=5),
'description': 'xxxxxxxxxxxxxxxxxxxx',
'emails': ['xxxxxxxx@xxxxxxxxxxxx.com'],
'slack_channels': ['#xxxxxxxxxxxxxxx']
},
'xxxxxxxxxxxxxxxxx': {
'acceptable_lag': timedelta(hours=5),
'description': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'emails': ['xxxxxxxx@xxxxxxxxxxxx.com'],
'slack_channels': ['#xxxxxxxxxxxxxxx']
},
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx': {
'acceptable_lag': timedelta(hours=0),
'description': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'emails': ['xxxxxxxx@xxxxxxxxxxxx.com'],
'slack_channels': ['#xxxxxxxxxxxxxxx']
}
}
