120 likes | 195 Views
HTML email and Python - a journey. Dave Cranwell. Clients. CampaignMonitor.com/css. Clients. Booo. No <style> No <link>. Hiss!. complete crap. Python to the rescue!. LULZ. Libraries. Python Package Index: http://pypi.python.org. Beautiful Soup Element Soup Element Tree lXML
E N D
HTML emailand Python- a journey Dave Cranwell.
Clients Dave Cranwell. HTML email and Python – a journey
CampaignMonitor.com/css Dave Cranwell. HTML email and Python – a journey
Clients Booo No <style> No <link> Hiss! complete crap Dave Cranwell. HTML email and Python – a journey
Python to the rescue! LULZ Dave Cranwell. HTML email and Python – a journey
Libraries Python Package Index: http://pypi.python.org • Beautiful Soup • Element Soup • Element Tree • lXML • Minidom • PyQuery • CSS Utils Dave Cranwell. HTML email and Python – a journey
Libraries • Beautiful Soup • Element Soup • Element Tree • lXML • Minidom • PyQuery • CSS Utils Dave Cranwell. HTML email and Python – a journey
lXML • Pythonic binding of libxml2 (C) • up to 20 X faster than Beautiful Soup at parsing * • Includes CSSSelect, which converts a CSS 2.1 selector into an Xpath * http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Dave Cranwell. HTML email and Python – a journey
Introducing... Dave Cranwell. HTML email and Python – a journey
Whats happening? • lXML parses HTML and converts to an eTree • CSSUtils parses CSS rules into objects • Loop over CSS rules converting each to XPath with CSSSelect • Create CSSStyleDeclaration for each element affected by a CSS rule • Contains details of the tag as well as the combined styles applied • Loop over eTree and serialised matching CSSStyleDeclarations into the “style” attribute. Dave Cranwell. HTML email and Python – a journey
No Google App engine, sadly • No C libsx • Pure Python only x • (and java) • Piss easy to setup P • Bloody cool P Dave Cranwell. HTML email and Python – a journey
FIN Dave Cranwell. david@torchbox.com