Restruturando
[cascardo/irpf-gui.git] / src / ocupacoes.py
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