diff --git a/src/main-impots-gouv.py b/src/main-impots-gouv.py new file mode 100644 index 0000000000000000000000000000000000000000..7e5a356b12dc44877f1babb5c0414c200ef029c2 --- /dev/null +++ b/src/main-impots-gouv.py @@ -0,0 +1,72 @@ +import matplotlib.pyplot as plt + +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.remote.webelement import WebElement +# import chromedriver_binary + +url = 'https://www3.impots.gouv.fr/simulateur/calcul_impot/2021/simplifie/index.htm' +defaultWait = 5 + +def q(s): + return driver.find_element_by_css_selector(s) + +print("setting options", flush=True) +options = Options() +# binary = '/usr/bin/google-chrome-beta' +# options.binary_location = binary +options.add_argument("--headless") +options.add_argument("--no-sandbox") +chrome_driver = webdriver.Chrome( + options=options +) +# chrome_driver = webdriver.Chrome() +chrome_driver.wait = WebDriverWait(chrome_driver, defaultWait) +WebElement.q = q +WebElement.driver = chrome_driver +driver = chrome_driver + +min = 24000 +max = 48000 +step = 50 +salaries = range(min, max, step) +values = [] + +print("starting app", flush=True) + +def estimate(salary): + print(f"estimating taxes for ${salary}", flush=True) + chrome_driver.get(url) + q('#B0DA').send_keys('1993') + q('#B1AG').send_keys(str(salary)) + q('a[href="javascript:check()"]').click() + # return { 'salaire': float(salary), 'acompte': 0.0 } + return { + 'salaire': float(salary), + 'droits_simples': float(q('input[name="IDRS2"]' ).get_attribute('value')), + 'revenu_ref': float(q('input[name="REVKIRE"]' ).get_attribute('value')), + 'plafond': float(q('input[name="PERPPLAFTV"]').get_attribute('value')), + 'taux': float(q('input[name="RASTXFOYER"]').get_attribute('value')), + 'acompte': float(q('input[name="RASTOTFM"]' ).get_attribute('value')) + } + +def plot(data): + names = data[0].keys() + salaries = [] + values = [] + for value in data: + salaries.append(value['salaire']) + del value['salaire'] + values.append(value['acompte']) + plt.plot(salaries, values, 'ro') + plt.ylabel('impots') + plt.xlabel('salaire') + plt.show() + +for salary in salaries: + values.append(estimate(salary)) + +# chrome_driver.close() +print("showing plot", flush=True) +plot(values)