bbb: Use namedtuples for the parsed values
Makes this a bit more readable rather than raw tuples Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
6cea27d3f2
commit
4e680a534e
17
bbb.py
17
bbb.py
|
@ -10,23 +10,29 @@
|
|||
#
|
||||
|
||||
__all__ = [
|
||||
'CursorEvent',
|
||||
'parse_cursor_xml',
|
||||
'PresentEvent',
|
||||
'SlideRef',
|
||||
'parse_deskshare_xml',
|
||||
'parse_shapes_svg',
|
||||
]
|
||||
|
||||
|
||||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
import lxml.etree
|
||||
|
||||
|
||||
CursorEvent = namedtuple('CursorEvent', 'ts x y')
|
||||
|
||||
def parse_cursor_xml(filename):
|
||||
rv = []
|
||||
xml_doc = lxml.etree.parse(filename)
|
||||
for element in xml_doc.xpath("//recording/event"):
|
||||
px, py = [float(x) for x in element.getchildren()[0].text.split()]
|
||||
rv.append((
|
||||
rv.append(CursorEvent(
|
||||
float(element.get("timestamp")),
|
||||
px,
|
||||
py,
|
||||
|
@ -34,13 +40,16 @@ def parse_cursor_xml(filename):
|
|||
return rv
|
||||
|
||||
|
||||
PresentEvent = namedtuple('CursorEvent', 'ts_in ts_out slide')
|
||||
SlideRef = namedtuple('SlideRef', 'deck_id page')
|
||||
|
||||
def parse_deskshare_xml(filename):
|
||||
rv = []
|
||||
xml_doc = lxml.etree.parse(filename)
|
||||
for element in xml_doc.xpath("//recording/event"):
|
||||
st = float(element.get("start_timestamp"))
|
||||
et = float(element.get("stop_timestamp"))
|
||||
rv.append( (st, et, None) )
|
||||
rv.append( PresentEvent(st, et, None) )
|
||||
return rv
|
||||
|
||||
|
||||
|
@ -63,10 +72,10 @@ def parse_shapes_svg(filename):
|
|||
m = re.match('^presentation/([0-9a-fA-F]{40,64}-[0-9]+)/slide-([0-9]+).png$', href)
|
||||
if not m:
|
||||
raise RuntimeError('Invalid presentation page link')
|
||||
slide = (m.group(1), int(m.group(2)))
|
||||
slide = SlideRef(m.group(1), int(m.group(2)))
|
||||
|
||||
# Append
|
||||
rv.append((
|
||||
rv.append(PresentEvent(
|
||||
float(element.get('in')),
|
||||
float(element.get('out')),
|
||||
slide
|
||||
|
|
Loading…
Reference in New Issue