1 / 12

HTML email and Python - a journey

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

osric
Download Presentation

HTML email and Python - a journey

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HTML emailand Python- a journey Dave Cranwell.

  2. Clients Dave Cranwell. HTML email and Python – a journey

  3. CampaignMonitor.com/css Dave Cranwell. HTML email and Python – a journey

  4. Clients Booo No <style> No <link> Hiss! complete crap Dave Cranwell. HTML email and Python – a journey

  5. Python to the rescue! LULZ Dave Cranwell. HTML email and Python – a journey

  6. 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

  7. Libraries • Beautiful Soup • Element Soup • Element Tree • lXML • Minidom • PyQuery • CSS Utils Dave Cranwell. HTML email and Python – a journey

  8. 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

  9. Introducing... Dave Cranwell. HTML email and Python – a journey

  10. 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

  11. 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

  12. FIN Dave Cranwell. david@torchbox.com

More Related