I have xml file that contains some kind of playlist and when I parse it I want to sum frames.
XML looks something like this:
<starttime>02-02-2021 01:30:52:154</starttime><frames>94</frames> <starttime>02-02-2021 01:50:52:124</starttime><frames>96</frames> <starttime>02-02-2021 02:50:52:124</starttime><frames>120</frames> <starttime>02-02-2021 02:50:52:124</starttime><frames>180</frames>
and I want to add to the dictionary and calculate frames in a specific hour so I have sliced date, min, sec... and leave only the hour, but in that case, I can't add multiple values to a key, because the last value overwrites all before. So I don't know how to sum all frames to that key.
the result should be
{'01':'200','02':'300'}
import os import xml.etree.ElementTree as ET from timecode import Timecode file = '/home/Myxml.xml' dom = ET.parse(file) lista = dom.findall('PLAYLIST') listXML = [] for l in lista: type_md = l.find('type') # COMMERCIAL start_time = l.find('starttime') # početak emitiranja frames = l.find('frames') # TC Duration if type_md.text == 'COMMERCIAL': listXML.append(start_time.text[11:-10]) listXML.append(frames.text) listXML = list(zip(listXML[::2], listXML[1::2])) clock_dict = {} for x in listXML: x_dict = list(zip(x[::2], x[1::2])) clock_dict.update(x_dict) print(clock_dict) # print(clock_dict)
https://stackoverflow.com/questions/66501866/python-sum-frames-from-dictionary-value March 06, 2021 at 10:41AM
没有评论:
发表评论