Created
July 2, 2016 10:55
-
-
Save giampaolo44/55b590b7cb9271cc55e5bbd5f6ef3413 to your computer and use it in GitHub Desktop.
Look at Gmail filters' XML
This file contains 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/python | |
# coding=utf-8 | |
import xml.etree.ElementTree as etree #importa la libreria per xml | |
tree = etree.parse('test_py-mailFilters.xml') #fa il parsing del file xml | |
root = tree.getroot() #lo prende tutto | |
entries = root.findall('{http://www.w3.org/2005/Atom}entry') #poi estrae solo le entries | |
contatore =0 | |
for el in entries: #per ogni elemento 'entry' dell'xml | |
contatore +=1 | |
etichetta = '' | |
for child in el: #per ogni sottoelemento | |
if child.attrib.get('name') == 'label': #se ha l'attributo 'label' | |
etichetta = child.attrib.get('value') #qual'è? mettilo in etichetta | |
elif child.attrib.get('name') == 'forwardTo': #se ha il 'forwardTo' | |
etichetta = etichetta +',forwardTo' #segnalalo in etichetta | |
elif child.attrib.get('name') == 'shouldTrash': #se ha l'attributo 'shouldTrash' | |
etichetta = etichetta +',shouldTrash' #segnalalo in etichetta | |
if etichetta != '': | |
print contatore , ',', etichetta | |
else: | |
print contatore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment