Forked from frafra/gist:73f2a13061ee47dda6458ae59a25d8ce
Created
July 3, 2016 21:23
-
-
Save giampaolo44/42b2d2757d5abfff5801b4b58e79b5c2 to your computer and use it in GitHub Desktop.
Look at Gmail filters' XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import xml.etree.ElementTree as ET | |
def getProperties(entry, ns): | |
for app_property in entry.findall('apps:property', ns): | |
name = app_property.attrib['name'] | |
if name in ('forwardTo', 'shouldTrash'): | |
yield name | |
ns = { | |
'atom':'http://www.w3.org/2005/Atom', | |
'apps':'http://schemas.google.com/apps/2006', | |
} | |
tree = ET.parse('test_py-mailFilters.xml') | |
for index, entry in enumerate(tree.findall('atom:entry', ns)): | |
app_property = entry.find('apps:property[@name="label"]', ns) | |
label = app_property.attrib['value'] if app_property != None else '' | |
print('%d,%s,%s' %(index, label, ','.join(getProperties(entry, ns)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
versione compatibile con Py 2.x e 3.x
(sempre by frafra)