from datetime import datetime
import pathlib
import json
list((pathlib.Path()/'srv1').iterdir())
txtfiles = list((pathlib.Path()/'textfiles').iterdir())
txtfiles
[WindowsPath('textfiles/transcript1-1.txt'),
WindowsPath('textfiles/transcript2-1.txt'),
WindowsPath('textfiles/transcript3-1.txt'),
WindowsPath('textfiles/transcript4-1.txt'),
WindowsPath('textfiles/transcript4-2.txt'),
WindowsPath('textfiles/transcript5-1.txt'),
WindowsPath('textfiles/transcript5-2.txt'),
WindowsPath('textfiles/transcript5-3.txt'),
WindowsPath('textfiles/transcript6-1.txt')]
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)
for txtfile in txtfiles:
make_json(txtfile)
json.dump()
a = '0:00:00.000,0:00:04.440\n'
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}'
'00:00'
dt.minute
0