Restruturando
authorEduardo Elias Camponez <camponez@gmail.com>
Sat, 4 May 2013 14:17:03 +0000 (11:17 -0300)
committerEduardo Elias Ferreira <edusf@linux.vnet.ibm.com>
Mon, 6 May 2013 12:48:09 +0000 (09:48 -0300)
* Move os arquivos fonte para src

bens.py [deleted file]
contribuinte.py [deleted file]
municipios.py [deleted file]
ocupacoes.py [deleted file]
src/bens.py [new file with mode: 0644]
src/contribuinte.py [new file with mode: 0644]
src/municipios.py [new file with mode: 0644]
src/ocupacoes.py [new file with mode: 0644]

diff --git a/bens.py b/bens.py
deleted file mode 100644 (file)
index 02a8499..0000000
--- a/bens.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-#   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
-from contribuinte import Contribuinte
-
-class Bem:
-    def __init__(self, el):
-        self.bem = el
-        def get_attr(self, attr):
-            if attr in self.bem.attributes.keys():
-                return self.bem.attributes[attr].nodeValue
-            return None
-        def set_attr(self, attr, val):
-            self.bem.attributes[attr].nodeValue = val
-
-class Bens:
-    def __init__(self, contribuinte):
-        self.contribuinte = contribuinte
-                self.bens = self.contribuinte.dados.getElementsByTagName("bens")[0]
-                self.items = []
-                for i in self.bens.getElementsByTagName("item"):
-                    self.items.append(Bem(i))
-        def _get_attr(self, el, attr):
-            if attr in el.attributes.keys():
-                return el.attributes[attr].nodeValue
-            return None
-        def _set_attr(self, el, attr, val):
-            el.attributes[attr].nodeValue = val
-        def get_bens(self, attr):
-            return self._get_attr(self.bens, attr)
-        def set_bens(self, attr, val):
-            self._set_attr(self.bens, attr, val)
-
-if __name__ == '__main__':
-    import sys
-        contribuinte = Contribuinte(sys.argv[1])
-        bens = Bens(contribuinte)
-        print "anterior: " + bens.get_bens("totalExercicioAnterior")
-        print "atual: " + bens.get_bens("totalExercicioAtual")
-        for i in bens.items:
-            print i.get_attr("valorExercicioAtual") + " " + i.get_attr("discriminacao")
-
-# vim:tabstop=4:expandtab:smartindent
diff --git a/contribuinte.py b/contribuinte.py
deleted file mode 100644 (file)
index eaa1e71..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-#   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 Contribuinte:
-    def __init__(self, cpf):
-        self.cpf = self._minimize_cpf(cpf)
-        if not self._validate_cpf(self.cpf):
-            raise RuntimeError("Invalid CPF")
-        self.declaracao = self._find_id()
-        self.dados = xml.dom.minidom.parse("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf))
-        self.contribuinte = self.dados.getElementsByTagName("contribuinte")[0]
-    def _find_id(self):
-        cpf = self._normalize_cpf(self.cpf)
-        self.declaracoes = xml.dom.minidom.parse("aplicacao/dados/iddeclaracoes.xml")
-        for i in self.declaracoes.childNodes[0].childNodes:
-            if "cpf" in i.attributes.keys():
-                if i.attributes["cpf"].nodeValue == cpf:
-                    return i
-        return None
-    # CPF normalizado se parece com 000.000.000-00
-    def _normalize_cpf(self, cpf):
-        ncpf = ""
-        for i in cpf:
-            if len(ncpf) == 3 or len(ncpf) == 7:
-                ncpf += '.'
-            if len(ncpf) == 11:
-                ncpf += '-'
-            if len(ncpf) == 14:
-                break
-            if ord(i) >= ord('0') and ord(i) <= ord('9'):
-                ncpf += i
-        if len(ncpf) != 14:
-            raise RuntimeError("Invalid CPF")
-        return ncpf
-    # CPF minimizado se parece com 01234567890
-    def _minimize_cpf(self, cpf):
-        ncpf = bytearray(self._normalize_cpf(cpf))
-        del ncpf[11]
-        del ncpf[7]
-        del ncpf[3]
-        return str(ncpf)
-    def _validate_cpf(self, cpf):
-        ncpf = self._minimize_cpf(cpf)
-        if len(ncpf) != 11:
-            return False
-        v = (11 - sum(map(lambda x: x[0]*x[1], zip(range(10, 1, -1), map(lambda x: ord(x) - ord('0'), ncpf[0:9]))))) % 11
-        if v >= 10:
-            v = 0
-        if v != ord(ncpf[9]) - ord('0'):
-            return False
-        v = (11 - sum(map(lambda x: x[0]*x[1], zip(range(11, 1, -1), map(lambda x: ord(x) - ord('0'), ncpf[0:10]))))) % 11
-        if v >= 10:
-            v = 0
-        if v != ord(ncpf[10]) - ord('0'):
-            return False
-        return True
-    def save(self):
-        self.dados.writexml(open("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf), "w"))
-        self.declaracoes.writexml(open("aplicacao/dados/iddeclaracoes.xml", "w"))
-    def _get_attr(self, el, attr):
-        if attr in el.attributes.keys():
-            return el.attributes[attr].nodeValue
-        return None
-    def _set_attr(self, el, attr, val):
-        el.attributes[attr].nodeValue = val
-    def get_declaracao(self, attr):
-        return self._get_attr(self.declaracao, attr)
-    def set_declaracao(self, attr, val):
-        self._set_attr(self.declaracao, attr, val)
-    def get_nome(self):
-        return self.get_declaracao("nome")
-    def set_nome(self, nome):
-        self.set_declaracao("nome", nome)
-    def get_contribuinte(self, attr):
-        if attr == "nome":
-            return self.get_nome()
-        return self._get_attr(self.contribuinte, attr)
-    def set_contribuinte(self, attr, val):
-        if attr == "nome":
-            self.set_nome(val)
-        self._set_attr(self.contribuinte, attr, val)
-
-contribuinte_attributes = [
-        "nome",
-        "dataNascimento",
-        "tituloEleitor",
-        "doencaDeficiencia",
-        "exterior",
-        "pais",
-        "cep",
-        "uf",
-        "cidade",
-        "municipio",
-        "tipoLogradouro",
-        "logradouro",
-        "numero",
-        "complemento",
-        "bairro",
-        "bairroExt",
-        "cepExt",
-        "logradouroExt",
-        "numeroExt",
-        "complementoExt",
-        "ocupacaoPrincipal",
-        "codigoExterior",
-        "ddd",
-        "telefone",
-        "naturezaOcupacao",
-        ]
-
-declaracao_attributes = [
-        "dataUltimoAcesso",
-        "declaracaoRetificadora",
-        "enderecoDiferente",
-        "enderecoMACRede",
-        "exercicio",
-        "nome",
-        "numReciboDecRetif",
-        "numeroReciboDecAnterior",
-        "resultadoDeclaracao",
-        "tipoDeclaracao",
-        "tipoDeclaracaoAES",
-        "transmitida",
-        "versaoBeta"
-        ]
-
-if __name__ == '__main__':
-    import sys
-    contribuinte = Contribuinte(sys.argv[1])
-    print "Carregando CPF " + contribuinte._normalize_cpf(sys.argv[1])
-    if contribuinte._validate_cpf(sys.argv[1]):
-        print "CPF valido"
-    else:
-        print "CPF invalido"
-        sys.exit(1)
-    if len(sys.argv) == 4:
-        print "Valor anterior: " + contribuinte.get_contribuinte(sys.argv[2])
-        contribuinte.set_contribuinte(sys.argv[2], sys.argv[3])
-        print "Valor atual: " + contribuinte.get_contribuinte(sys.argv[2])
-        print "Salvando..."
-        contribuinte.save()
-    else:
-        print "\nCONTRIBUINTE:"
-        for i in contribuinte_attributes:
-            val = contribuinte.get_contribuinte(i)
-            if val == None:
-                val = ""
-            print i + ": " + val
-        print "\nDECLARACAO:"
-        for i in declaracao_attributes:
-            val = contribuinte.get_declaracao(i)
-            if val == None:
-                val = ""
-            print i + ": " + val
-
-# vim:tabstop=4:expandtab:smartindent
diff --git a/municipios.py b/municipios.py
deleted file mode 100644 (file)
index 380ffa7..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#
-#   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')
-
-# vim:tabstop=4:expandtab:smartindent
diff --git a/ocupacoes.py b/ocupacoes.py
deleted file mode 100644 (file)
index 5f5ec17..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#
-#   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 Ocupacoes:
-    def __init__(self):
-        self.xml = xml.dom.minidom.parse("res/ocupacoesPrincipal.xml")
-        self.l = []
-        self.g = {}
-        self._list()
-        self._group()
-    def _list(self):
-        for i in self.xml.childNodes[0].childNodes:
-            if "COL4" in i.attributes.keys():
-                self.l.append((i.attributes["COL1"].nodeValue, \
-                        i.attributes["COL2"].nodeValue, \
-                        i.attributes["COL3"].nodeValue, \
-                        i.attributes["COL4"].nodeValue))
-                def list(self):
-                    return self.l
-    def _group(self):
-        for i in self.l:
-            if i[1] not in self.g:
-                self.g[i[1]] = []
-            self.g[i[1]].append(i)
-    def groups(self):
-        return self.g
-    def get_ocupacao(self, code):
-        for i in self.l:
-            if i[0] == code:
-                return i
-        return None
-
-if __name__ == '__main__':
-    ocupacoes = Ocupacoes()
-    l = ocupacoes.groups()
-    for i in sorted(l):
-        print l[i][0][1] , l[i][0][2]
-        for j in l[i]:
-            print "\t %s %s" % (j[0], j[3])
-    print
-    print ocupacoes.get_ocupacao('212')[3]
-
-# vim:tabstop=4:expandtab:smartindent
diff --git a/src/bens.py b/src/bens.py
new file mode 100644 (file)
index 0000000..02a8499
--- /dev/null
@@ -0,0 +1,57 @@
+#
+#   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
+from contribuinte import Contribuinte
+
+class Bem:
+    def __init__(self, el):
+        self.bem = el
+        def get_attr(self, attr):
+            if attr in self.bem.attributes.keys():
+                return self.bem.attributes[attr].nodeValue
+            return None
+        def set_attr(self, attr, val):
+            self.bem.attributes[attr].nodeValue = val
+
+class Bens:
+    def __init__(self, contribuinte):
+        self.contribuinte = contribuinte
+                self.bens = self.contribuinte.dados.getElementsByTagName("bens")[0]
+                self.items = []
+                for i in self.bens.getElementsByTagName("item"):
+                    self.items.append(Bem(i))
+        def _get_attr(self, el, attr):
+            if attr in el.attributes.keys():
+                return el.attributes[attr].nodeValue
+            return None
+        def _set_attr(self, el, attr, val):
+            el.attributes[attr].nodeValue = val
+        def get_bens(self, attr):
+            return self._get_attr(self.bens, attr)
+        def set_bens(self, attr, val):
+            self._set_attr(self.bens, attr, val)
+
+if __name__ == '__main__':
+    import sys
+        contribuinte = Contribuinte(sys.argv[1])
+        bens = Bens(contribuinte)
+        print "anterior: " + bens.get_bens("totalExercicioAnterior")
+        print "atual: " + bens.get_bens("totalExercicioAtual")
+        for i in bens.items:
+            print i.get_attr("valorExercicioAtual") + " " + i.get_attr("discriminacao")
+
+# vim:tabstop=4:expandtab:smartindent
diff --git a/src/contribuinte.py b/src/contribuinte.py
new file mode 100644 (file)
index 0000000..eaa1e71
--- /dev/null
@@ -0,0 +1,171 @@
+#
+#   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 Contribuinte:
+    def __init__(self, cpf):
+        self.cpf = self._minimize_cpf(cpf)
+        if not self._validate_cpf(self.cpf):
+            raise RuntimeError("Invalid CPF")
+        self.declaracao = self._find_id()
+        self.dados = xml.dom.minidom.parse("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf))
+        self.contribuinte = self.dados.getElementsByTagName("contribuinte")[0]
+    def _find_id(self):
+        cpf = self._normalize_cpf(self.cpf)
+        self.declaracoes = xml.dom.minidom.parse("aplicacao/dados/iddeclaracoes.xml")
+        for i in self.declaracoes.childNodes[0].childNodes:
+            if "cpf" in i.attributes.keys():
+                if i.attributes["cpf"].nodeValue == cpf:
+                    return i
+        return None
+    # CPF normalizado se parece com 000.000.000-00
+    def _normalize_cpf(self, cpf):
+        ncpf = ""
+        for i in cpf:
+            if len(ncpf) == 3 or len(ncpf) == 7:
+                ncpf += '.'
+            if len(ncpf) == 11:
+                ncpf += '-'
+            if len(ncpf) == 14:
+                break
+            if ord(i) >= ord('0') and ord(i) <= ord('9'):
+                ncpf += i
+        if len(ncpf) != 14:
+            raise RuntimeError("Invalid CPF")
+        return ncpf
+    # CPF minimizado se parece com 01234567890
+    def _minimize_cpf(self, cpf):
+        ncpf = bytearray(self._normalize_cpf(cpf))
+        del ncpf[11]
+        del ncpf[7]
+        del ncpf[3]
+        return str(ncpf)
+    def _validate_cpf(self, cpf):
+        ncpf = self._minimize_cpf(cpf)
+        if len(ncpf) != 11:
+            return False
+        v = (11 - sum(map(lambda x: x[0]*x[1], zip(range(10, 1, -1), map(lambda x: ord(x) - ord('0'), ncpf[0:9]))))) % 11
+        if v >= 10:
+            v = 0
+        if v != ord(ncpf[9]) - ord('0'):
+            return False
+        v = (11 - sum(map(lambda x: x[0]*x[1], zip(range(11, 1, -1), map(lambda x: ord(x) - ord('0'), ncpf[0:10]))))) % 11
+        if v >= 10:
+            v = 0
+        if v != ord(ncpf[10]) - ord('0'):
+            return False
+        return True
+    def save(self):
+        self.dados.writexml(open("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf), "w"))
+        self.declaracoes.writexml(open("aplicacao/dados/iddeclaracoes.xml", "w"))
+    def _get_attr(self, el, attr):
+        if attr in el.attributes.keys():
+            return el.attributes[attr].nodeValue
+        return None
+    def _set_attr(self, el, attr, val):
+        el.attributes[attr].nodeValue = val
+    def get_declaracao(self, attr):
+        return self._get_attr(self.declaracao, attr)
+    def set_declaracao(self, attr, val):
+        self._set_attr(self.declaracao, attr, val)
+    def get_nome(self):
+        return self.get_declaracao("nome")
+    def set_nome(self, nome):
+        self.set_declaracao("nome", nome)
+    def get_contribuinte(self, attr):
+        if attr == "nome":
+            return self.get_nome()
+        return self._get_attr(self.contribuinte, attr)
+    def set_contribuinte(self, attr, val):
+        if attr == "nome":
+            self.set_nome(val)
+        self._set_attr(self.contribuinte, attr, val)
+
+contribuinte_attributes = [
+        "nome",
+        "dataNascimento",
+        "tituloEleitor",
+        "doencaDeficiencia",
+        "exterior",
+        "pais",
+        "cep",
+        "uf",
+        "cidade",
+        "municipio",
+        "tipoLogradouro",
+        "logradouro",
+        "numero",
+        "complemento",
+        "bairro",
+        "bairroExt",
+        "cepExt",
+        "logradouroExt",
+        "numeroExt",
+        "complementoExt",
+        "ocupacaoPrincipal",
+        "codigoExterior",
+        "ddd",
+        "telefone",
+        "naturezaOcupacao",
+        ]
+
+declaracao_attributes = [
+        "dataUltimoAcesso",
+        "declaracaoRetificadora",
+        "enderecoDiferente",
+        "enderecoMACRede",
+        "exercicio",
+        "nome",
+        "numReciboDecRetif",
+        "numeroReciboDecAnterior",
+        "resultadoDeclaracao",
+        "tipoDeclaracao",
+        "tipoDeclaracaoAES",
+        "transmitida",
+        "versaoBeta"
+        ]
+
+if __name__ == '__main__':
+    import sys
+    contribuinte = Contribuinte(sys.argv[1])
+    print "Carregando CPF " + contribuinte._normalize_cpf(sys.argv[1])
+    if contribuinte._validate_cpf(sys.argv[1]):
+        print "CPF valido"
+    else:
+        print "CPF invalido"
+        sys.exit(1)
+    if len(sys.argv) == 4:
+        print "Valor anterior: " + contribuinte.get_contribuinte(sys.argv[2])
+        contribuinte.set_contribuinte(sys.argv[2], sys.argv[3])
+        print "Valor atual: " + contribuinte.get_contribuinte(sys.argv[2])
+        print "Salvando..."
+        contribuinte.save()
+    else:
+        print "\nCONTRIBUINTE:"
+        for i in contribuinte_attributes:
+            val = contribuinte.get_contribuinte(i)
+            if val == None:
+                val = ""
+            print i + ": " + val
+        print "\nDECLARACAO:"
+        for i in declaracao_attributes:
+            val = contribuinte.get_declaracao(i)
+            if val == None:
+                val = ""
+            print i + ": " + val
+
+# vim:tabstop=4:expandtab:smartindent
diff --git a/src/municipios.py b/src/municipios.py
new file mode 100644 (file)
index 0000000..380ffa7
--- /dev/null
@@ -0,0 +1,57 @@
+#
+#   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')
+
+# vim:tabstop=4:expandtab:smartindent
diff --git a/src/ocupacoes.py b/src/ocupacoes.py
new file mode 100644 (file)
index 0000000..5f5ec17
--- /dev/null
@@ -0,0 +1,58 @@
+#
+#   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 Ocupacoes:
+    def __init__(self):
+        self.xml = xml.dom.minidom.parse("res/ocupacoesPrincipal.xml")
+        self.l = []
+        self.g = {}
+        self._list()
+        self._group()
+    def _list(self):
+        for i in self.xml.childNodes[0].childNodes:
+            if "COL4" in i.attributes.keys():
+                self.l.append((i.attributes["COL1"].nodeValue, \
+                        i.attributes["COL2"].nodeValue, \
+                        i.attributes["COL3"].nodeValue, \
+                        i.attributes["COL4"].nodeValue))
+                def list(self):
+                    return self.l
+    def _group(self):
+        for i in self.l:
+            if i[1] not in self.g:
+                self.g[i[1]] = []
+            self.g[i[1]].append(i)
+    def groups(self):
+        return self.g
+    def get_ocupacao(self, code):
+        for i in self.l:
+            if i[0] == code:
+                return i
+        return None
+
+if __name__ == '__main__':
+    ocupacoes = Ocupacoes()
+    l = ocupacoes.groups()
+    for i in sorted(l):
+        print l[i][0][1] , l[i][0][2]
+        for j in l[i]:
+            print "\t %s %s" % (j[0], j[3])
+    print
+    print ocupacoes.get_ocupacao('212')[3]
+
+# vim:tabstop=4:expandtab:smartindent