def write_date_variascompt(self, mes, ano): driver = self.driver # mes, ano = self.set_get_compt_file(m_cont, y_cont, file_type=False).split('-') # print(f'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {mes}---{ano}') sleep(5) iframe = driver.find_element_by_xpath("//iframe[@name='principal']") driver.switch_to.frame(iframe) self.tag_wait(driver, 'input') driver.find_element_by_xpath('//input[@name="mes"]').send_keys(mes) driver.find_element_by_xpath('//input[@name="ano"]').send_keys(ano)
def fazendo_principal(self, constr=False): """ o click do prestador está no init :return: """ driver = self.driver if not constr: self.calls_write_date() try: driver.find_element_by_xpath( '/html/body/form/table[2]/tbody/tr[3]/td/table/tbody/tr[2]/td/table/tbody/tr[1]/td[4]/a' ).click() # driver.find_elements_by_xpath("//*[contains(text(), 'Encerrar Escrituração ')]")[0].click() try: sleep(2) driver.find_elements_by_xpath( "//*[contains(text(), 'CLIQUE AQUI')]")[0].click() # PrintScreenFinal(clien) except (NoSuchElementException, IndexError): print( 'Provavelmente já foi declarada... Ou tem que encerrar sem movimento' ) # ................. except NoSuchElementException: print('Exception line 140, sem PRESTADOR') # print("BACKEI. Aqui vai ser a parte 2") driver.switch_to.default_content() iframe = driver.find_element_by_xpath("//iframe[@name='header']") sleep(2.5) driver.switch_to.frame(iframe) driver.find_element_by_xpath( '//img[contains(@src,"bt_menu__06_off.jpg")]').click() driver.switch_to.default_content() iframe = driver.find_element_by_xpath("//iframe[@name='principal']") driver.switch_to.frame(iframe) """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TOMADOR """ cont = 0 for i in range(2): sleep(3) a = driver.find_elements_by_tag_name('a') print(len(a)) a[4].click() sleep(1.5) try: driver.find_elements_by_xpath( "//*[contains(text(), 'CLIQUE AQUI')]")[0].click() break except IndexError: try: driver.find_element_by_link_text('Menu Principal').click() except NoSuchElementException: driver.find_element_by_link_text('OK').click()
def loga_simples(self, CNPJ, CPF, CodSim, CLIENTE): driver = self.driver driver.get( 'https://www8.receita.fazenda.gov.br/SimplesNacional/controleAcesso/Autentica.aspx?id=60' ) driver.get( 'https://www8.receita.fazenda.gov.br/SimplesNacional/controleAcesso/Autentica.aspx?id=60' ) while str(driver.current_url.strip()).endswith('id=60'): self.tags_wait('body') self.tags_wait('html') self.tags_wait('input') # driver.find_elements_by_xpath("//*[contains(text(), 'CNPJ:')]")[0].click() # pygui.hotkey('tab', interval=0.5) cpcp = driver.find_element_by_name( 'ctl00$ContentPlaceHolder$txtCNPJ') cpcp.clear() cpcp.send_keys(CNPJ) cpfcpf = driver.find_element_by_name( 'ctl00$ContentPlaceHolder$txtCPFResponsavel') cpfcpf.clear() cpfcpf.send_keys(CPF) cod = driver.find_element_by_name( 'ctl00$ContentPlaceHolder$txtCodigoAcesso') cod.clear() cod.send_keys(CodSim) cod_caract = driver.find_element_by_id( 'txtTexto_captcha_serpro_gov_br') btn_som = driver.find_element_by_id( 'btnTocarSom_captcha_serpro_gov_br') sleep(2.5) btn_som.click() sleep(.5) cod_caract.click() print(f'PRESSIONE ENTER P/ PROSSEGUIR, {CLIENTE}') press_key_b4('enter') while True: try: submit = driver.find_element_by_xpath( "//input[@type='submit']").click() break except (NoSuchElementException, ElementClickInterceptedException): print('sleepin' 'g, line 167. Cadê o submit?') driver.refresh() sleep(5) sleep(5)
def opta_script(self): driver = self.driver try: # #################################################### opta self.get_sub_site('/RegimeApuracao/Optar', self.current_url) # driver.execute_script("""window.location.href += '/RegimeApuracao/Optar'""") from selenium.webdriver.support.ui import Select anocalendario = Select(driver.find_element_by_id('anocalendario')) anocalendario.select_by_value('2021') self.find_submit_form() # competencia competencia, caixa = '0', '1' driver.find_element_by_css_selector( f"input[type='radio'][value='{competencia}']").click() self.find_submit_form() sleep(2.5) # driver.find_element_by_id('btnSimConfirm').click() try: driver.implicitly_wait(10) self.click_ac_elementors( driver.find_element_by_class_name('glyphicon-save')) except NoSuchElementException: input('input Não consegui') else: print('Não fui exceptado') # ######################################################## except NoSuchElementException: pass finally: driver.get(self.current_url) driver.execute_script( """window.location.href += '/declaracao?clear=1'""") sleep(2.5)
def intelligence_cnpj_test_element(self, CNPJ): """:return: element create_inteligence, somente """ driver = self.driver def elem_with_text(elem, searched): _tag = driver.find_element_by_xpath( f"//{elem}[contains(text(),'{searched.rstrip()}')]") return _tag self.tags_wait('html', 'span') sleep(5) # nextcl = elem_with_text("span", "Alterar perfil de acesso") # nextcl.click() driver.find_element_by_id('btnPerfil').click() # altera perfil e manda o cnpj self.tags_wait('label') cnpj = elem_with_text("label", "Procurador de pessoa jurídica - CNPJ") cnpj.click() sleep(.5) self.send_keys_anywhere(CNPJ) sleep(1) self.send_keys_anywhere(Keys.TAB) self.send_keys_anywhere(Keys.ENTER) sleep(1) # driver.find_element_by_class_name('access-button').click() # sleep(10) antigo = driver.current_url """I GOT IT""" # switch_to.frame... element = driver.find_element_by_class_name('mensagemErro').text element = element.strip() print(element) driver.get( 'https://sinac.cav.receita.fazenda.gov.br/simplesnacional/aplicacoes/atspo/pgdasd2018.app/' ) return element
def __init__(self, firstcompt=None): from os import chdir, path, getcwd from time import sleep from functools import partial sh_names = ['GISS'] # input(len(after_read['CNPJ'])) self.compt_atual = super().get_compt_only() excel_file_name = super().excel_file_path() for sh_name in sh_names: # agora eu posso fazer downloalds sem me preocupar tendo a variável path mshExcelFile = pd.ExcelFile(excel_file_name) msh = mshExcelFile.parse(sheet_name=str(sh_name)) col_str_dic = {column: str for column in list(msh)} msh = mshExcelFile.parse(sheet_name=str(sh_name), dtype=col_str_dic) READ = self.le_excel_each_one(msh) self.after_read = self.readnew_lista(READ, False) after_read = self.after_read with open('pgdas_fiscal_oesk/data_clients_files/giss_passwords.txt' ) as f: __senhas = f.read().split(',') [print(s) for s in __senhas] used_after_read = list(after_read.values())[:5] __giss_cnpj, __feito, __logar, self.__construcao, _anotacoes = used_after_read for i in range(len(__feito)): _giss_cliente, _feito, _logar, self._construcao, anotacoes = ( __giss_cnpj[i], __feito[i], __logar[i], self.__construcao[i], _anotacoes[i]) if _logar.strip() == "GISS LOGIN" or _feito.strip() != "": continue # ################################ essa lógica acima ...................................... continue for loop_compt in self.ate_atual_compt(first_compt=firstcompt): [ print(a) for a in self.ate_atual_compt(first_compt=firstcompt) ] # self.driver = ginfess_driver() self.driver = pgdas_driver() super().__init__(self.driver) driver = self.driver driver.get(weblink) chrome = driver cont_senha = 0 while True: # TxtIdent driver.find_element_by_xpath( '//input[@name="TxtIdent"]').send_keys(_logar) driver.find_element_by_xpath( '//input[@name="TxtSenha"]').send_keys( __senhas[cont_senha]) print(f'Senha: {__senhas[cont_senha]}', end=' ') cont_senha += 1 driver.find_element_by_link_text("Acessar").click() try: WebDriverWait(chrome, 5).until( expected_conditions.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') alert = chrome.switch_to.alert alert.accept() print("estou no try") driver.execute_script("window.history.go(-1)") except TimeoutException: print("no alert, sem alerta, exceptado") break # holy """ for m in range(m_cont): # print(self.write_date(m_cont, y_cont)) mes, ano = self.set_get_compt_file(m_cont, y_cont, file_type=False).split('-') print(mes, ano) input() """ month, year = loop_compt.split('-') self.calls_write_date = partial( self.write_date_variascompt, month, year) try: iframe = driver.find_element_by_xpath( "//iframe[@name='header']") driver.switch_to.frame(iframe) except NoSuchElementException: driver.execute_script( "window.location.href=('/tomador/tomador.asp');") if self._construcao.lower().strip() != 'sim': driver.find_element_by_xpath( "//img[contains(@src,'images/bt_menu__05_off.jpg')]" ).click() else: print('Construção Civil?') self.constr_civil() driver.switch_to.default_content() sleep(1) if self._construcao.lower() == 'sim': self.fazendo_principal(True) else: self.fazendo_principal() driver.implicitly_wait(10) self.driver.close() print('GISS encerrado!')
def constr_civil(self): # parei nessa belezinha aqui, tomador e prestador tão ok XPATH = "//*[contains(text(), '- Serviço da Construção Civil')]", "//*[contains(text(), '- Demais Serviços')]" driver = self.driver driver.find_element_by_xpath( '//img[contains(@src,"bt_menu__06_off.jpg")]').click() sleep(2) driver.switch_to.default_content() self.calls_write_date() for contX in range(len(XPATH)): driver.switch_to.default_content() sleep(2) iframe = driver.find_element_by_xpath("//iframe[@name='header']") driver.switch_to.frame(iframe) construcao = self._construcao driver.find_element_by_xpath( '//img[contains(@src,"bt_menu__07_off.jpg")]').click() driver.switch_to.default_content() sleep(2) iframe = driver.find_element_by_xpath( "//iframe[@name='principal']") driver.switch_to.frame(iframe) driver.find_element_by_xpath(XPATH[contX]).click() # XPATH # input("faça os processos daqui pra baixo") if contX == 0: ttt = 5.0 for i in range(2): sleep(ttt) ttt -= 2.5 driver.find_element_by_xpath( "//*[contains(text(), 'Encerrar Competência')]").click( ) try: WebDriverWait(driver, 3).until( expected_conditions.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') # ENCERRADO driver.switch_to.alert.accept() sleep(5) except (NoAlertPresentException, TimeoutException): print('no alert') driver.refresh() # input('drive refresh') elif contX == 1: driver.find_element_by_xpath( "//*[contains(text(), 'Encerrar Escrituração')]").click() driver.find_elements_by_xpath( "//*[contains(text(), 'CLIQUE AQUI')]")[0].click() # ENCERRADO sleep(5)
def simples_and_ecac_utilities(self, option, compt): """ :param int option: somente de 1 a 2, sendo :param str compt: competência 1 -> Gerar Das somente se for consolidar para outra DATA 2 -> Gerar Protocolos :return: """ # estou na "declaração", aqui faço o que quiser from datetime import datetime now_year = str(datetime.now().year) compt = ''.join(v for v in compt if v.isdigit()) month_compt = compt[:2] year_compt = compt[2:] driver = self.driver current_url = self.current_url link_gera_das, download_protocolos_das = 'Das/PorPa', '/Consulta' if option == 2: self.get_sub_site(download_protocolos_das, current_url) driver.implicitly_wait(5) if now_year != year_compt: self.send_keys_anywhere(year_compt) self.find_submit_form() sleep(3.5) comp_clic = driver.find_elements_by_class_name('pa') lenc = len(comp_clic) - 1 comp_clic[lenc].click() for i in range(3): sleep(2) self.send_keys_anywhere(Keys.TAB) self.send_keys_anywhere(Keys.ENTER) elif option == 1: # gera das venc_month_compt = int(month_compt) + 1 venc = self.get_last_business_day_of_month(venc_month_compt, int(year_compt)) retifica_p_dia = f'{venc}{venc_month_compt:02d}{year_compt}' self.get_sub_site(link_gera_das, current_url) self.tags_wait('input') driver.implicitly_wait(10) periodo = driver.find_element_by_id('pa') periodo.send_keys(compt) self.find_submit_form() sleep(2.5) # if len(driver.find_elements_by_id('msgBox')) == 0 # CASO NÃO EXISTA O DAS consolida = driver.find_element_by_id('btnConsolidarOutraData') consolida.click() sleep(2.5) validade_id = 'txtDataValidade' driver.execute_script( f"document.getElementById('{validade_id}').focus();") validade_change = driver.find_element_by_id(validade_id) for e, val in enumerate(retifica_p_dia): validade_change.send_keys(val) if e == 0: sleep(.25) sleep(1) driver.find_element_by_id('btnDataValidade').click() # coloquei a validade # gerei das driver.implicitly_wait(5) self.find_submit_form() # GERAR DAS else: return False
def DECLARA(self, compt, sheet_id, valor_declarado, my_new_3valores, cont_ret_n_ret): driver = self.driver after_READ = self.after_READ declara_client = self.now_person try: js_confirm = driver.find_element_by_id('jsMsgBoxConfirm') """ tk_msg('F2 para somente gerar os últimos 3 arquivos de declarações.\n F4 para RETIFICAR' '\nF10 p/ consolidar para ultima data do mês\n\n' '\nF11 Para passar para o próximo cliente \n\n' 'Espere ou clique OK', 10) """ # não consegui callback em mensagem which_one = press_keys_b4('f2', 'f4', 'f10', 'f11') print(type(which_one)) print(which_one) if which_one == 'f2': # consultar declarações, baixar arquivos self.simples_and_ecac_utilities(2, compt) elif which_one == 'f4': print('RETIFICA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') driver.execute_script(""" window.location.href = '/SimplesNacional/Aplicacoes/ATSPO/pgdasd2018.app/Pa/Retificar'""" ) # raise vai fazer a ratificação raise NoSuchElementException elif which_one == 'f10': self.simples_and_ecac_utilities(1, compt) # F10 p/ consolidar para ultima data do mês elif which_one == 'f11': pass except NoSuchElementException: print('ALREADY FALSE') sleep(2.5) inp = driver.find_elements_by_tag_name('input')[0] sleep(3) print('R$', valor_declarado) inp = driver.find_elements_by_tag_name('input')[0] inp.clear() inp.send_keys(valor_declarado) for i in range(2): inp.send_keys(Keys.TAB) self.find_submit_form() sleep(3) print(f'{valor_declarado}, olha o valor aqui') if sheet_id == 0 or valor_declarado == '': for i in range(2): self.tags_wait('form') sleep(3) try: self.find_submit_form() except NoSuchElementException: driver.find_elements_by_class_name( 'btn-success')[1].click() # em teste # ISS, index 1 elif sheet_id == 1: def trata_retencoes(v): try: if float(eval(str(v).replace(',', '.'))) == 0: v = '' except SyntaxError: # return v v = v finally: return v if not my_new_3valores: """ SemRetencao = self.trata_money_excel(after_READ['NÃO RETIDO'][cont_ret_n_ret]) ComRetencao = self.trata_money_excel(after_READ['RETIDO'][cont_ret_n_ret]) # padronizar essa parte """ SemRetencao = self.trata_money_excel( after_READ['Sem Retenção'][cont_ret_n_ret]) ComRetencao = self.trata_money_excel( after_READ['Com Retenção'][cont_ret_n_ret]) # input('if not') else: SemRetencao = self.trata_money_excel( [v for v in my_new_3valores[2].values()][0]) ComRetencao = self.trata_money_excel( [v for v in my_new_3valores[1].values()][0]) # input('else') print('~~~~~~~~~~~~' * 30) print(f'ANTES, Com Retenção: {ComRetencao}, Sem:{SemRetencao}') ComRetencao = trata_retencoes(ComRetencao) SemRetencao = trata_retencoes(SemRetencao) print('~~~~~~~~~~~~' * 30) print(f'Com Retenção: {ComRetencao}, Sem:{SemRetencao}') # input('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') print('~~~~~~~~~~~~' * 30) self.tags_wait('a') prestacao_serv = driver.find_element_by_id('btn-exibe-todos') prestacao_serv.click() sleep(2.5) if SemRetencao != '' and ComRetencao == '': print('Só teve SEM RETENÇÃO') self.send_keys_anywhere(Keys.TAB, 17 + 1) self.send_keys_anywhere(Keys.ENTER) self.find_submit_form() # SUBMITA retenções s/ valor ainda sleep(2.5) self.send_keys_anywhere(valor_declarado) self.send_keys_anywhere(Keys.ENTER) # submita o valor sleep(2.5) self.send_keys_anywhere(Keys.ENTER) # calcular sleep(3) self.find_submit_form() sleep(2) elif SemRetencao != '' and ComRetencao != '': print('Retido e não retido.') self.send_keys_anywhere(Keys.TAB, 17 + 1) self.send_keys_anywhere(Keys.ENTER) self.send_keys_anywhere(Keys.TAB, 1) self.send_keys_anywhere(Keys.ENTER) self.find_submit_form() # SUBMITA retenções s/ valor ainda sleep(2) self.send_keys_anywhere(SemRetencao) self.send_keys_anywhere(Keys.TAB, 9) self.send_keys_anywhere(ComRetencao) self.send_keys_anywhere(Keys.ENTER) # calcular sleep(3) self.find_submit_form() sleep(2) elif SemRetencao == '' and ComRetencao != '': print('\033[1;33mSó teve COM RETENÇÃO\033[m') self.send_keys_anywhere(Keys.TAB, 17 + 2) # +2 é COM retenção self.send_keys_anywhere(Keys.ENTER) self.find_submit_form() # SUBMITA retenções s/ valor ainda sleep(2.5) self.send_keys_anywhere(valor_declarado) self.send_keys_anywhere(Keys.ENTER) # submita o valor sleep(2.5) self.send_keys_anywhere(Keys.ENTER) # calcular sleep(3) self.find_submit_form() sleep(2) # o valor já tá sendo tratado acima no IF master, mas ok if valor_declarado != '': sleep(.5) driver.find_elements_by_class_name( 'btn-success')[1].click() # self.GERA_PGDAS2 acima sleep(3.5) driver.implicitly_wait(5) try: self.find_submit_form() except NoSuchElementException: driver.find_elements_by_class_name( 'btn-success')[1].click() # DOWNLOAD feito pois já está setado nos argumentos do driver elif sheet_id == 2: # ICMS cont_vrv = cont_ret_n_ret VRV = after_READ['Venda ou Revenda'][cont_vrv] print(f'Venda ou revenda: {VRV}') vrv = VRV.lower().strip() self.tags_wait('a') prestacao_serv = driver.find_element_by_id('btn-exibe-todos') prestacao_serv.click() sleep(2.5) if vrv == 'revenda': self.send_keys_anywhere(Keys.TAB, 3) self.send_keys_anywhere(Keys.ENTER) elif vrv == 'venda': self.send_keys_anywhere(Keys.TAB, 7) self.send_keys_anywhere(Keys.ENTER) # o valor já tá sendo tratado acima no IF master, mas ok if valor_declarado != '': sleep(2) self.find_submit_form() self.tags_wait('body', 'input', 'form') sleep(1.5) self.send_keys_anywhere(valor_declarado) sleep(1.5) self.send_keys_anywhere(Keys.ENTER) # calcular sleep(2.5) self.tags_wait('body', 'input', 'form') self.send_keys_anywhere(Keys.ENTER) # transmitir sleep(2) self.find_submit_form() sleep(.5) driver.find_elements_by_class_name( 'btn-success')[1].click() sleep(2.5) self.find_submit_form() # gerou # ~~~~~~~~~~~~~SEM-RETENÇÃO-universal~~~~~~~~~~~~~# print('AFTER IFs') # engloba add = '-SemMovimento' if valor_declarado == '' else '' save = self.certif_feito(self.client_path, add=add) driver.save_screenshot(save) self.simples_and_ecac_utilities(2, compt)
def change_ecac_client(self, CNPJ): """:return: vai até ao site de declaração do ECAC.""" driver = self.driver def elem_with_text(elem, searched): _tag = driver.find_element_by_xpath( f"//{elem}[contains(text(),'{searched.rstrip()}')]") return _tag self.tags_wait('html', 'span') sleep(5) # nextcl = elem_with_text("span", "Alterar perfil de acesso") # nextcl.click() btn_perfil = WebDriverWait(self.driver, 20).until( expected_conditions.presence_of_element_located( (By.ID, 'btnPerfil'))) self.click_ac_elementors(btn_perfil) # altera perfil e manda o cnpj self.tags_wait('label') cnpj = elem_with_text("label", "Procurador de pessoa jurídica - CNPJ") cnpj.click() sleep(.5) self.send_keys_anywhere(CNPJ) sleep(1) self.send_keys_anywhere(Keys.TAB) self.send_keys_anywhere(Keys.ENTER) sleep(1) # driver.find_element_by_class_name('access-button').click() # sleep(10) antigo = driver.current_url """I GOT IT""" # switch_to.frame... sleep(5) driver.get( 'https://sinac.cav.receita.fazenda.gov.br/simplesnacional/aplicacoes/atspo/pgdasd2018.app/' ) sleep(2.5) driver.get(antigo) driver.get( 'https://cav.receita.fazenda.gov.br/ecac/Aplicacao.aspx?id=10009&origem=menu' ) driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) sleep(2) while True: try: driver.find_element_by_xpath( '//span[@class="glyphicon glyphicon-off"]').click() driver.refresh() break except ElementClickInterceptedException: print( '---> PRESSIONE ESC PARA CONTINUAR <--- glyphicon-off intercepted' ) press_key_b4('esc') except NoSuchElementException: print( '---> PRESSIONE ESC PARA CONTINUAR NoSuchElement glyphicon-off' ) press_key_b4('esc') driver.get( 'https://sinac.cav.receita.fazenda.gov.br/simplesnacional/aplicacoes/atspo/pgdasd2018.app/' ) driver.implicitly_wait(5) break sleep(3) driver.switch_to.default_content() """I GOT IT""" # chegou em todo mundo... driver.get( 'https://sinac.cav.receita.fazenda.gov.br/simplesnacional/aplicacoes/atspo/pgdasd2018.app/' ) driver.implicitly_wait(5)
def __init__(self): """ :param compt_file: from GUI # remember past_only arg from self.get_atual_competencia """ import pandas as pd from autoesk_main.pgdas_fiscal_oesk.relacao_nfs import tres_valores_faturados # O vencimento DAS(seja pra qual for a compt) está certo, haja vista que se trata do mes atual sh_names = 'sem_mov', 'G5_ISS', 'G5_ICMS' intelligence_existence = self.intelligence_existence_done( 'CERT_vs_LOGIN.xlsx') inteligence_db = {'CLIENT': [], 'CERT x LOGIN': []} client_db_name = inteligence_db['CLIENT'] cert_x_login = inteligence_db['CERT x LOGIN'] cont_inteligence = -1 compt = super().get_compt_only().replace('-', '/') excel_file_name = super().excel_file_path() for sh_name in sh_names: # agora eu posso fazer downloalds sem me preocupar tendo a variável path mshExcelFile = pd.ExcelFile(excel_file_name) msh = mshExcelFile.parse(sheet_name=str(sh_name)) col_str_dic = {column: str for column in list(msh)} msh = mshExcelFile.parse(sheet_name=str(sh_name), dtype=col_str_dic) READ = self.le_excel_each_one(msh) self.after_READ = self.readnew_lista(READ, False) after_READ = self.after_READ # if sh_name not in 'sem_mov': print(cont_inteligence) print(f'cont inteligence plan {sh_name}') for i, CNPJ in enumerate(after_READ['CNPJ']): if 'G5' in sh_name: cont_inteligence += 1 # ####################### A INTELIGENCIA EXCEL ESTÁ SEM OS SEM MOVIMENTOS NO MOMENTO CLIENTE = after_READ['Razão Social'][i] JA_DECLARED = after_READ['Declarado'][i].upper().strip() CodSim = after_READ['Código Simples'][i] CPF = after_READ['CPF'][i] cont_ret_n_ret = i if CLIENTE == '': break self.now_person = CLIENTE self.client_path = self.files_pathit(CLIENTE) # if not existe o arquivo my_wised_check_path_file -> no momento atual, existe def cria_inteligence(): print('Intelligence does not exist') self.driver = pgdas_driver(self.client_path) self.loga_cert() # driver.set_window_position(-1055, 0) # muda o client, no ECAC, é apenas uma função teste element = self.intelligence_cnpj_test_element(CNPJ) if element != '': client_db_name.append(CLIENTE) cert_x_login.append('loginComCodSim') self.loga_simples(CNPJ, CPF, CodSim, CLIENTE) print( f'Não preciso logar (if element != "") p/ criar inteligence. \n{CLIENTE}, ' f'por isso, break') """ print(f'PRESSIONE ENTER P/ PROSSEGUIR, {CLIENTE}') press_key_b4('enter') while True: try: driver.implicitly_wait(5) submit = driver.find_element_by_xpath("//input[@type='submit']").click() break except (NoSuchElementException, ElementClickInterceptedException): print('sleeping, line 167. Cadê o submit?') driver.refresh() driver.implicitly_wait(5) # implicitly_wait -> if element was already appeared, it'll not wait. """ else: client_db_name.append(CLIENTE) cert_x_login.append('certificado') print('SUCESSO, CERTIFICADO, ', CLIENTE) # checa se a inteligencia não existe try: # driver.set_window_position(initial['x'], initial['y']) driver.close() # está ok o unbound me ajuda except UnboundLocalError: pass if isinstance( intelligence_existence, list) and JA_DECLARED not in [ 'S', 'OK', 'FORA' ] and cont_inteligence >= 0: __client_path = self.client_path self.driver = pgdas_driver(__client_path) driver = self.driver super().__init__(driver) driver.implicitly_wait(2) # initial = driver.get_window_position() driver.get('https://www.google.com.br') print('ecac_or_simples') try: ecac_or_simples = intelligence_existence[ cont_inteligence][1] except IndexError: print('FINISH') break # input(intelligence_existence[cont_inteligence][0]) # -> O NOME DO CLIENTE my_new_3valores = tres_valores_faturados(self.client_path) print(my_new_3valores, '----> my_new_3valores') def return_valor(): if sh_names.index(sh_name) != 0: if sh_names.index(sh_name) == 1: if my_new_3valores: print(my_new_3valores[0]) VALOR = [ v for v in my_new_3valores[0].values() ][0] else: VALOR = after_READ['Valor'][i] if VALOR == '0': # or VALOR == '': VALOR = '' return VALOR else: VALOR = after_READ['Valor'][i] if VALOR == '0': # or VALOR == '': VALOR = '' return VALOR if 'zerou' in str(VALOR).lower(): VALOR = '' else: if '.' not in str(VALOR): VALOR = f'{VALOR},00' elif VALOR != '': VALOR = f'{float(VALOR):.2f}' VALOR = self.trata_money_excel(VALOR) else: self.icms_prossegue = False # não está em uso ainda else: VALOR = '' print('VALOR BEFORE RETURN', VALOR) return VALOR VALOR = return_valor() # Tratei o que dá pra fazer no certificado e o que não dá if ecac_or_simples == 'certificado': self.loga_cert() # loga ECAC, Insere CNPJ self.change_ecac_client(CNPJ) self.current_url = driver.current_url self.opta_script() if self.m() == 12 else None else: self.loga_simples(CNPJ, CPF, CodSim, CLIENTE) self.current_url = driver.current_url self.opta_script() if self.m() == 12 else None # faz outras declaracoes se necessarias """NÃO FUNCIONANDO CORRETAMENTE AINDA""" # if self.check_make_pendencies(): self.compt_typist(compt) self.DECLARA(compt, sh_names.index(sh_name), VALOR, my_new_3valores, cont_ret_n_ret) print('CLOSE DRIVE EM 5 SEGS') sleep(5) driver.close() elif cont_inteligence == -1: if JA_DECLARED not in ['S', 'OK']: print('estou em sem movimento, vou arrumar ainda') __client_path = self.client_path self.driver = pgdas_driver(__client_path) driver = self.driver super().__init__(self.driver) if CodSim != '-' and CodSim != '': # Código simples existe # SEM MOVIMENTO self.loga_simples(CNPJ, CPF, CodSim, CLIENTE) else: # Código sim inexistente self.loga_cert() self.change_ecac_client(CNPJ) self.current_url = driver.current_url self.opta_script() if self.m() == 12 else None VALOR = 'zerou' print('!!!ZEROU!!!') self.compt_typist(compt) # faz outras declaracoes se necessarias if self.check_make_pendencies(): for compt_p2 in self.check_make_pendencies(): print(compt_p2, 'compt_p2') self.compt_typist( compt_p2, '/'.join( driver.current_url.split('/')[:-1])) self.DECLARA(compt_p2, sh_names.index(sh_name), '', False, cont_ret_n_ret) self.compt_typist( compt, '/'.join(driver.current_url.split('/')[:-1])) else: self.compt_typist(compt) self.DECLARA(compt, sh_names.index(sh_name), VALOR, 'zerou', cont_ret_n_ret) elif not intelligence_existence: # se não existir vai criar. cria_inteligence() else: print( f'{CLIENTE} \nJA DECLARADO: {JA_DECLARED}\n-----------------' )
def __init__(self): print('filespathteste') """ """ import pandas as pd from default.webdriver_utilities.pre_drivers import pgdas_driver # O vencimento DAS(seja pra qual for a compt) está certo, haja vista que se trata do mes atual sh_names = ['_Dívidas'] compt = super().get_compt_only() excel_file_name = super().excel_file_path() for sh_name in sh_names: # agora eu posso fazer downloalds sem me preocupar tendo a variável path mshExcelFile = pd.ExcelFile(excel_file_name) msh = mshExcelFile.parse(sheet_name=str(sh_name)) col_str_dic = {column: str for column in list(msh)} msh = mshExcelFile.parse(sheet_name=str(sh_name), dtype=col_str_dic) READ = self.le_excel_each_one(msh) self.after_READ = self.readnew_lista(READ, False) after_READ = self.after_READ for i, CNPJ in enumerate(after_READ['CNPJ']): CLIENTE = after_READ['Razão Social'][i] JA_DECLARED = after_READ['Declarado'][i] simples_or_ativa = after_READ['tipo'][i] if JA_DECLARED not in ['S', 'OK', 'FORA']: self.client_path = self.files_pathit( 'Dívidas_Simples_' + CLIENTE, compt) __client_path = self.client_path self.driver = pgdas_driver(__client_path) super().__init__(self.driver) driver = self.driver self.loga_cert() self.change_ecac_client(CNPJ) driver.find_element_by_id('linkHome').click() if simples_or_ativa == 'simples nacional': driver.find_element_by_link_text( 'Simples Nacional').click() driver.find_element_by_link_text( 'Solicitar, acompanhar e emitir DAS de parcelamento' ).click() driver.implicitly_wait(10) driver.switch_to.frame( driver.find_element_by_id('frmApp')) empel = driver.find_element_by_id( 'ctl00_contentPlaceH_linkButtonEmitirDAS') empel.click() WebDriverWait(self.driver, 20).until( expected_conditions.presence_of_element_located( (By.XPATH, '//input[@value="Continuar"]'))).click() imprimires = WebDriverWait(self.driver, 20).until( expected_conditions. presence_of_all_elements_located( (By.LINK_TEXT, 'Imprimir'))) for imprimir in imprimires: imprimir.click() # Imprimir driver.switch_to.default_content() elif simples_or_ativa == 'dívida ativa': driver.find_element_by_link_text( 'Dívida Ativa da União').click() driver.find_element_by_link_text( 'Débitos Inscritos em Dívida Ativa da União' ).click() driver.switch_to.window(driver.window_handles[1]) driver.implicitly_wait(10) sispar_url = f"{'/'.join(driver.current_url.split('/')[:-1])}/sispar" driver.get(sispar_url) try: WebDriverWait(self.driver, 10).until( expected_conditions. presence_of_element_located( (By.TAG_NAME, 'button'))) self.tag_with_text('button', 'Acessar o SISPAR').click() except NoSuchElementException: WebDriverWait(self.driver, 10).until( expected_conditions. presence_of_element_located( (By.TAG_NAME, 'button'))) self.tag_with_text('button', 'Acessar').click() # provavelmente uma mudança no sistema mas vou validar # WebDriverWait(self.driver, 10).until(expected_conditions.new_window_is_opened(driver.window_handles)) WebDriverWait(self.driver, 10).until( expected_conditions.number_of_windows_to_be(3)) driver.switch_to.window(driver.window_handles[2]) driver.execute_script( "PrimeFaces.addSubmitParam('cabecalho',{'cabecalho:j_idt45':'cabecalho:j_idt45'}).submit('cabecalho');" ) self.click_elements_by_tt('DEFERIDO E CONSOLIDADO') sleep(1) WebDriverWait(self.driver, 20).until( expected_conditions.presence_of_element_located( (By.ID, 'formListaDarf:idbtnDarf'))).click() WebDriverWait(self.driver, 20).until( expected_conditions.presence_of_element_located( (By.TAG_NAME, 'table'))) compt_dividas_ativas = f'{self.m():02d}/{self.y()}' print(compt_dividas_ativas) sleep(7) dris = driver.find_elements_by_css_selector( ".colunaAlinhaCentro") elemitidos = driver.find_elements_by_css_selector( f"[title*='Já emitido']") for el in elemitidos: el.click() sleep(.5) self.send_keys_anywhere(Keys.ENTER) print('breakou, baixou JÁ EMITIDOS') self.contains_title('Não emitido').click() sleep(.5) self.send_keys_anywhere(Keys.ENTER) self.click_ac_elementors( WebDriverWait(self.driver, 20).until( expected_conditions. presence_of_element_located(( By.ID, 'formResumoParcelamentoDarf:dlgInformacoesEmissaoDarf' )))) self.send_keys_anywhere(Keys.TAB) self.send_keys_anywhere(Keys.TAB) self.send_keys_anywhere(Keys.ENTER) self.click_ac_elementors( WebDriverWait(self.driver, 20).until( expected_conditions. presence_of_element_located(( By.ID, 'formResumoParcelamentoDarf:emitirDarf')))) WebDriverWait(self.driver, 5) else: print('ACABOU, break') break