#!/usr/bin/env python # coding: utf-8 # In[66]: from datetime import datetime import pathlib import json # In[ ]: list((pathlib.Path()/'srv1').iterdir()) # In[55]: txtfiles = list((pathlib.Path()/'textfiles').iterdir()) # In[56]: txtfiles # In[67]: def make_json(txtfile): my_dict = {} with txtfile.open() as f: cnt = 0 for line in f: if (cnt%3)==0: a = line a[0].split(',.') b = a.split(',')[0] dt = datetime.strptime(b.split('.')[0], '%H:%M:%S') tm = f'{dt.hour*60 + dt.minute:02d}' + ":" + f'{dt.second:02d}' if (cnt%3)==1: txt = line.strip() if (cnt%3)==2: my_dict[tm] = txt cnt += 1 json.dump(my_dict, txtfile.with_suffix('.json').open('w'), indent=2) # In[68]: for txtfile in txtfiles: make_json(txtfile) # In[ ]: json.dump() # In[16]: a = '0:00:00.000,0:00:04.440\n' # In[40]: a[0].split(',.') b = a.split(',')[0] dt = datetime.strptime(b.split('.')[0], '%H:%M:%S') f'{dt.hour + dt.minute:02d}' + ":" + f'{dt.second:02d}' # In[37]: dt.minute # In[ ]: