diff --git a/README.md b/README.md index f73e8a2..789b381 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,74 @@ darf -==== \ No newline at end of file +==== + +São 4 programinhas para calcular o valor do DARF a ser pago ao se receber +ações GOOG através de GSU. + +Dependências: + +* [Python 3.2][py] ou mais recente +* [dateutil][dateutil] +* [lxml][lxml] + +[py]: http://python.org/ +[dateutil]: http://labix.org/python-dateutil +[lxml]: http://lxml.de/ + +exchangerate.py +--------------- + +Usa UOL e Google Finance para pegar o valor da ação GOOG em uma certa data e o +valor do dólar no último dia útil da primeira quinzena do mês anterior. + + ./exchangerate.py 20-Jan-2012 + usdbrl@15-Dec-2011: 1.860800 goog@20-Jan-2012: 585.990000 + +A data pode ser digitada em qualquer formato suportado pelo +[`dateutil.parser.parse`][parse]. + +[parse]: http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c + +tax.py +------ + +Realiza uma busca na tabela progressiva do imposto para fazer a mesma conta +que o [carnê-leão][carneleao] faz. + + ./tax.py 5000 2012-Jan + R$5000.000000 @Jan-2012 gives tax of R$618.470000 + +O valor de entrada (no exemplo acima, 5000) corresponde à seguinte fórmula: + + num. de ações × valor da ação × cotação do dólar + +[carneleao]: http://www.receita.fazenda.gov.br/PessoaFisica/CarneLeao/default.htm + +sicalc.py +--------- + +Recebe o valor de imposto e usa o sicalc para gerar o DARF. + + # cpf com 12 dígitos, mês, valor + ./sicalc.py 12345678909 2012-Jan 618.47 + Darf written at carne-leao-2012-Jan-darf-para-2012-Aug.html + +gsu_irpf.py +----------- + +É a cola de todos os programas anteriores. Recebe o CPF e o arquivo CSV +*transaction history* (exportado do [benefitaccess.com][mssb]) e gera todos os +DARFs, incluindo multa e juros se aplicável. Basta apenas escolher os que não +foram pagos e pagá-los. + + ./gsu_irpf.py 12345678909 sample_benefit_access_csv.csv + 2012-08-01: vested 3 shares for total value R$3872.00 (1 GSU = 632.68 @2012-08-01, 1 USD = 2.04 @2012-07-13) + 2012-03-26: vested 5 shares for total value R$5584.24 (1 GSU = 649.33 @2012-03-26, 1 USD = 1.72 @2012-02-15) + 2012-03-25: vested 5 shares for total value R$5526.27 (1 GSU = 642.59 @2012-03-25, 1 USD = 1.72 @2012-02-15) + --- + carne leao 2012-03: exterior 11110.51 imposto devido: 2298.86 + carne leao 2012-08: exterior 3872.00 imposto devido: 308.27 + Generated darf carne-leao-2012-Mar-darf-para-2012-Aug.html + Generated darf carne-leao-2012-Aug-darf-para-2012-Aug.html + Point your browser to file://.../index.html + +[mssb]: http://benefitaccess.com/ diff --git a/exchangerate.py b/exchangerate.py index 4874f3d..7d43ca1 100755 --- a/exchangerate.py +++ b/exchangerate.py @@ -1,4 +1,4 @@ -#!/usr/local/homebrew/bin/python3 +#!/usr/bin/env python3 import argparse import logging diff --git a/gsu_irpf.py b/gsu_irpf.py index e250a16..0ae3e76 100755 --- a/gsu_irpf.py +++ b/gsu_irpf.py @@ -1,4 +1,4 @@ -#!/usr/local/homebrew/bin/python3 +#!/usr/bin/env python3 import bisect import csv @@ -45,7 +45,6 @@ def __init__(self, output_dir): self.xchgdb = exchangerate.ExchangeRateDB('xchgrate') self.calculator = tax.LionTax('xchgrate') self.sicalc = sicalc.Sicalc() - self.darf_css='https://pagamento.serpro.gov.br/Darf/estiloDARF.css' def _ParseTransactions(self, benefit_access_csv): reader = csv.reader(benefit_access_csv) @@ -89,7 +88,7 @@ def Generate(self, benefit_access_csv, cpf, startdate): index_file = os.path.join(self.output_dir, 'index.html') index = open(index_file, 'w') - index.write('Click me to fix ssl permissions if having rendering issues.

' % self.darf_css) + index.write('') index.write('Tax computation log

' % os.path.abspath(self.logfile_name)) summary = {} diff --git a/sicalc.py b/sicalc.py index d1c273f..233e075 100755 --- a/sicalc.py +++ b/sicalc.py @@ -1,4 +1,4 @@ -#!/usr/local/homebrew/bin/python3 +#!/usr/bin/env python3 from argparse import ArgumentParser, FileType from lxml.html import parse, submit_form, fromstring, tostring @@ -82,6 +82,8 @@ def GenerateDarf(self, cpf, monthstr, main_tax): darf = darf.replace('./', 'https://pagamento.serpro.gov.br/Darf/') # Remove 404 darf = darf.replace('', '') + # pagamento.serpro.gov.br has an expired SSL certificate. + darf = darf.replace('https://', 'http://') return darf if __name__ == '__main__': diff --git a/tax.py b/tax.py index 1274b8e..851e39a 100755 --- a/tax.py +++ b/tax.py @@ -1,4 +1,4 @@ -#!/usr/local/homebrew/bin/python3 +#!/usr/bin/env python3 # Crazy pickle wants this here class TaxTableEntry: @@ -41,19 +41,19 @@ def _crawlTaxTable(self, url): date = self._findDate(tree, v) celltype = i % 3 if celltype == 0: - m = re.search(' (\d\.\d\d\d),(\d\d)', txt) + m = re.search(' (\d\.\d\d\d),(\d\d)\s*', txt) assert(m) base = float(re.sub('\.', '', m.group(1))) + float(m.group(2))/100 if 'Acima' in txt: base = float("inf") elif celltype == 1: - m = re.search('>((\d?\d),(\d)|-)

', txt) + m = re.search(']*>\s*((\d?\d),(\d)|-)\s*

', txt) assert(m) tax = 0 if m.group(1) != '-': tax = float(m.group(2)) + float(m.group(3))/10 elif celltype == 2: - m = re.search('>((\d\d\d),(\d\d)|-)

', txt) + m = re.search(']*>\s*((\d\d\d),(\d\d)|-)\s*

', txt) assert(m) deduction = 0 if m.group(1) != '-':