Hello Marco,
Below is the datamart.json data.
{"logs": [{"filename": "ABC_PARIS_FILE_01.gz", "transmission_start": "23:03:2021 15:21", "transmission_end": "23:03:2021 15:22"},
{"filename": "ABC_INDIA_FILE_01.gz", "transmission_start": "23:03:2021 15:21", "transmission_end": "23:03:2021 15:22"},
{"filename": "ABC_PARIS_FILE_02.gz", "transmission_start": "23:03:2021 15:21", "transmission_end": "23:03:2021 15:22"},
{"filename": "ABC_INDIA_FILE_03.gz", "transmission_start": "23:03:2021 15:21", "transmission_end": "23:03:2021 15:22"},
{"filename": "ABC_INDIA_FILE_02.gz", "transmission_start": "23:03:2021 15:21", "transmission_end": "23:03:2021 15:22"}]}
Below is the code
import json
from tabulate import tabulate
with open('datamart.json','r') as f:
data = json.load(f)
for p in data['logs']:
if str(p['filename']).startswith("ABC_PARIS"):
pfilename = p['filename']
pstart = p['transmission_start']
pend = p['transmission_end']
print(pfilename,pstart,pend)
with open('datamart.json','r') as f:
data = json.load(f)
for p in data['logs']:
if str(p['filename']).startswith("ABC_INDIA"):
plfilename = p['filename']
plstart = p['transmission_start']
plend = p['transmission_end']
print(plfilename,plstart,plend)
table = [[pfilename,pstart,pend],[plfilename,plstart,plend]]
finaltablehtml=(tabulate(table, headers="firstrow", tablefmt="html"))
finaltabletext=(tabulate(table, headers="firstrow", tablefmt="grid"))
print(finaltabletext);
I am getting output as below.
+------------------------+--------------------+--------------------+
| ABC_PARIS_FILE_02.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+========================+====================+====================+
| ABC_INDIA_FILE_02.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+------------------------+--------------------+--------------------+
But i am looking for below output.
+========================+====================+====================+
| ABC_PARIS_FILE_01.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+------------------------+--------------------+--------------------+
| ABC_PARIS_FILE_02.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+========================+====================+====================+
| ABC_INDIA_FILE_01.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+------------------------+--------------------+--------------------+
| ABC_INDIA_FILE_02.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+========================+====================+====================+
| ABC_INDIA_FILE_03.gz | 23:03:2021 15:21 | 23:03:2021 15:22 |
+------------------------+--------------------+--------------------+
Can you please help me in getting output like above.
Thanks,
Hemanth.