-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_last_months_periodic_iva_declaration.py
68 lines (52 loc) · 2.58 KB
/
create_last_months_periodic_iva_declaration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from configparser import ConfigParser
from datetime import datetime
from time import sleep
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from util import login, minus_one_month
config = ConfigParser()
config.read("conf.ini")
def create_periodic_iva_declaration():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
driver.get(config.get("portal_financas", "url_consultar_facturas"))
login(driver, config)
sleep(2)
driver.fullscreen_window()
tables_recibos = driver.find_elements(By.CLASS_NAME, "tbody-border-primary")
assert len(tables_recibos) == 1
table = tables_recibos[0]
salary = int(
table.find_element(By.TAG_NAME, "tr").find_elements(By.TAG_NAME, "td")[3].text.strip(" €")[:-3].replace('.',
''))
driver.get(config.get("portal_financas", "url_declaracao_iva"))
driver.fullscreen_window()
# login(driver, config)
sleep(2)
today = datetime.today()
today_last_month = minus_one_month(today)
driver.find_element(By.XPATH, "//lf-select[@path = 'localizacaoSede']//input").send_keys("Continente" + Keys.ENTER)
driver.find_element(By.XPATH, "//lf-select[@path = 'anoDeclaracao']//input").send_keys(
f"{today_last_month.year}{Keys.ENTER}")
driver.find_element(By.XPATH, "//lf-select[@path = 'periodoDeclaracao']//input").send_keys(
today_last_month.strftime('%m') + Keys.DOWN + Keys.ENTER)
driver.find_element(By.XPATH, "//span[text() = ' Apuramento ']").click()
sim = "0"
nao = "1"
driver.find_element(By.XPATH,
f"//lf-radio[@path = 'temOperacoesAdquirenteComLiqImposto']//input[@value='{nao}']/../i").click()
salary_formatted = str(salary * 100)
driver.find_element(By.XPATH, "//lf-number[@path='btOperacoesIsentasComDeducao']//input").send_keys(
salary_formatted)
driver.find_element(By.XPATH,
"//*[contains(@class,'navigation-conclude')]//span[contains(text(), 'Entregar')]").click()
sleep(1)
driver.find_element(By.XPATH, "//*[contains(@class,'modal-footer')]//span[contains(text(), 'Entregar')]").click()
sleep(1)
driver.find_element(By.XPATH, "//span[text() = 'Autenticar']").click()
login(driver, config)
sleep(1)
if __name__ == "__main__":
create_periodic_iva_declaration()