kumisbespassung/steuer/einkommenssteuer.py

59 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
import configparser
import argparse
class TaxRates:
def __init__(self, config = "einkommenssteuer.ini"):
self.rates = {}
if config:
self.read_file(config)
def read_file(self, config, replace = True):
if replace:
self.rates = {}
parser = configparser.ConfigParser()
parser.read(config)
levels = [level for level in parser.sections() if level.startswith("tax")]
for level in levels:
self.add_rate(parser[level]["above"], parser[level]["rate"])
def add_rate(self, above, rate):
self.rates[int(above)] = int(rate)
def get_taxes(self, income):
taxes = 0
ratelist = list(self.rates.items())
for rate in range(len(ratelist)):
running = None
try:
if income > ratelist[rate + 1][0]:
running = ratelist[rate + 1][0] - ratelist[rate][0]
except:
pass
running = running or (income - ratelist[rate][0])
if running < 0:
break
taxes += running / 100 * ratelist[rate][1]
return taxes
def get_taxes(income):
return TaxRates().get_taxes(income)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("income", help="income to calculate taxes for", type=float)
args = parser.parse_args()
print(get_taxes(args.income))