--- /dev/null
+#
+# Copyright 2013 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# -*- mode: python; encoding: utf-8; -*-
+import xml.dom.minidom
+
+class Municipios:
+ def __init__(self, UF):
+ self.xml = xml.dom.minidom.parse("res/%s.xml" % (UF,))
+ self.l = []
+ self._list()
+ def _list(self):
+ for i in self.xml.childNodes[0].childNodes:
+ if "COL3" in i.attributes.keys():
+ self.l.append((i.attributes["COL1"].nodeValue, \
+ i.attributes["COL2"].nodeValue, \
+ i.attributes["COL3"].nodeValue))
+ def list(self):
+ return self.l
+ def get_municipio(self, code):
+ for i in self.l:
+ if i[0] == code:
+ return i
+ return None
+ def verify_cep(self, m, cep):
+ l = m[2][0:7]
+ h = m[2][9:16]
+ if cep >= l and cep <= h:
+ return True
+ return False
+
+if __name__ == '__main__':
+ municipios = Municipios('MG')
+ m = municipios.get_municipio('4877')
+ print m[1]
+ print municipios.verify_cep(m, '36880000')
+ print municipios.verify_cep(m, '05020000')
+
+ municipios = Municipios('SP')
+ m = municipios.get_municipio('7107')
+ print m[1]
+ print municipios.verify_cep(m, '05020000')
+ print municipios.verify_cep(m, '36880000')