Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Super simple na miru sity skript pro souhrnna hlaseni
# priklad vstupniho XML souboru - je nutne si ho upravit dle sveho
"""<?xml version="1.0" encoding="UTF-8"?>
<Pisemnost nazevSW="EPO MF ČR" verzeSW="39.15.1">
<DPHSHV verzePis="01.02">
<VetaD d_poddp="29.03.2017" dokument="SHV" k_uladis="DPH" mesic="8" rok="2017" shvies_forma="R" />
<VetaP c_pop="379" c_pracufo="2401" c_ufo="455" dic="<DIC>" jmeno="Daniel" naz_obce="<A>" prijmeni="<PRIJMENI>" psc="<PSC>" stat="ČESKÁ REPUBLIKA" titul="Bc." typ_ds="F" ulice="<ULICE>" />
<VetaR c_rad="1" c_vat="<VAT>" k_pln_eu="3" k_stat="GB" pln_hodnota="<CASTKA>" pln_pocet="1" por_c_stran="1" />
</DPHSHV>
<Kontrola>
<Uzivatel jmeno="null" prijmeni="null" />
<Soubor Delka="447" KC="014ba56ab9f482e93cfd5db2c0169347" Nazev="DPHSHV-9301251938-20170329-112452" c_ufo="455" />
</Kontrola>
</Pisemnost>
"""
import os
import argparse
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver import Chrome
from xml.etree import ElementTree
from os import path
parser = argparse.ArgumentParser(prog='Vyplnovacka souhrneho hlaseni',
description='Vyplni souhrnne hlaseni a odesle na FÚ',
formatter_class=argparse.HelpFormatter)
parser.add_argument('--castka', type=str, help='Castka na prvni radek', required=True)
parser.add_argument('--mesic', type=str, help='Mesic za ktere je hlaseni', required=True)
parser.add_argument('--input-xml', type=str, help='Cesta k defaultnimu XML souboru', required=True)
parser.add_argument('--email', type=str, help='Email pro potvrzeni', default='hnykda@gmail.com')
parser.add_argument('--output-dir', type=str, help='Cesta k adresari pro ulozeni assets', default='.')
args = parser.parse_args()
input_file = args.input_xml
CASTKA = args.castka
MESIC = args.mesic
EMAIL = args.email
OUT_DIR = args.output_dir
workdir = path.abspath(OUT_DIR)
out_xml_file = path.join(workdir, 'souhrnne_hlaseni_{}_{}.xml'.format(MESIC, CASTKA))
et = ElementTree.parse(input_file)
et.find('DPHSHV').find('VetaR').set('pln_hodnota', CASTKA)
et.find('DPHSHV').find('VetaD').set('mesic', MESIC)
et.write(out_xml_file, encoding='UTF-8')
# In[4]:
dr = Chrome()
dr.get('https://adisepo.mfcr.cz/adistc/adis/idpr_epo/epo2/spol/soubor_vyber.faces')
dr.find_element_by_xpath('//*[@id="formUpload:nacteniSouboru"]').send_keys(out_xml_file) # nacteni vystupniho souboru
dr.find_element_by_xpath('//*[@id="btnNacist"]').click() # nacist soubor
dr.find_element_by_xpath('//*[@id="frm:_idJsp56"]').click() # stranka pro odeslani
dr.find_element_by_xpath('//*[@id="form:zobrazeni_certifikatu"]/div[3]/label').click() # Nepodepisovat zadani
dr.find_element_by_xpath('//*[@id="email"]').send_keys(EMAIL)
def poslat_link_is_active(dr):
cls = dr.find_element_by_xpath('//*[@id="btnPodat"]')
return cls and cls.get_attribute('disabled') is None
WebDriverWait(dr, 10).until(poslat_link_is_active, 'Tlacitko poslat neni aktivni')
dr.find_element_by_xpath('//*[@id="btnPodat"]').click() # ODESLAT!
# download all assets
os.chdir(OUT_DIR)
dr.find_element_by_xpath('//*[@id="form:sub_zkr:_idJsp86"]').click() # potrvzeni
dr.find_element_by_xpath('//*[@id="form:_idJsp95"]').click() # potvrzeni 2
dr.find_element_by_xpath('//*[@id="odkazy"]/span/a').click() # xml file
dr.find_element_by_xpath('//*[@id="odkazy"]/div[1]/div[6]/span/a').click() # pdf tiskopis
# zapsat heslo a cislo
podaci_cislo = dr.find_element_by_xpath('//*[@id="odkazy"]/div[1]/table[1]/tbody/tr[1]/td[2]/span').text
pristupove_heslo = dr.find_element_by_xpath('//*[@id="odkazy"]/div[1]/table[1]/tbody/tr[2]/td[2]/span').text
with open('pristupove_udaje.txt', 'w') as ofile:
ofile.write(podaci_cislo + ',' + pristupove_heslo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment