#-#############################################
# FUNKCJE
# mBank_auto_skrypt v3.0.4
#-#############################################
def strip_space(value): #oczyszczanie ze spacji
return re.sub(r'\ ', '', value)
def strip_dspace(value): #usuwanie podwojnych niepotrzebnych spacji z tekstu
return re.sub(r'\ [\ ]+', ' ', value)
def get_konta(br, value='(.*)'):
#global wybor_period
#time.sleep(1)
response_get = br.open("https://www.mbank.com.pl/accounts_list.aspx") # otwarcie listy kont
# response_get.seek(5000)
strona = response_get.read().decode('iso8859-2')
strona = re.sub(r'
|', '\n', strona)
# magiczny regexp przed
#sz_konto = re.compile('\'account_details.aspx\',\'\',\'POST\',\'[^<]+href="#">([^0-9<]+)\ ([0-9\ ]+).*(bLast14=[^\']+).*\ href="#">([0-9-,\ ]+)\ ([A-Z]{3}).*">([0-9-,\ ]+)\ [A-Z]{3}
')
# magiczny regexp 2009.11
#sz_konto = re.compile('\'account_details.aspx\',\'\',\'POST\',\'[^<]+href="#">([^0-9<]+)\ ([0-9\ ]+).*\'account_oper_list.aspx\',\'\',\'POST\',\'([^\']+)\'[^<]+href="#">([0-9-,\ ]+)\ ([A-Z]{3})
.*">([0-9-,\ ]+)\ [A-Z]{3}
')
# magiczny regexp 2010.05
sz_konto = re.compile('\'/account_details.aspx\',\'\',\'POST\',\'[^<]+href="#">([^0-9<]+)\ ([0-9\ ]+).*\'/account_oper_list.aspx\',\'\',\'POST\',\'([^\']+)\'[^<]+href="#">([0-9-,\ ]+)\ ([A-Z]{3})
.*">([0-9-,\ ]+)\ [A-Z]{3}
')
r_konta = []
for konto_temp in list(sz_konto.findall(strona)):
konto_temp = list(konto_temp)
# odwracanie zmiennych, zeby zachowac kolejnosc
temp = konto_temp[2]
konto_temp[2] = konto_temp[1]
konto_temp[1] = konto_temp[0]
konto_temp[0] = temp
#
konto_temp[2] = strip_space(konto_temp[2])
konto_temp[3] = strip_space(konto_temp[3])
konto_temp[5] = strip_space(konto_temp[5])
if re.match(value, str(konto_temp[2])):
r_konta.append(konto_temp)
return r_konta
def get_trans(br, value='', valuea='ALL'):
global wybor_period
#time.sleep(1)
br.open("https://www.mbank.com.pl/accounts_list.aspx") # powrot na liste kont
# magiczny regexp
sz_grep = re.compile('<(.*\n)')
# magiczny regexp przed 2009.11
#sz_trans1 = re.compile('span>([0-9-]+)([0-9-]+).*iNumber=([0-9]+).*cCodeOper=([0-9]+).*href="#">([^<]+)([^<]+)([0-9]+)([^<]+).*">([0-9-\ ,]+)\ [A-Z]+
.*">([0-9-\ ,]+)\ ([A-Z]+)\n')
#sz_trans2 = re.compile('span>([0-9-]+)([0-9-]+).*iNumber=([0-9]+).*cCodeOper=([0-9]+).*href="#">([^<]+)([^<]+)()().*">([0-9-\ ,]+)\ [A-Z]+.*">([0-9-\ ,]+)\ ([A-Z]+)
\n')
#sz_trans3 = re.compile('span>([0-9-]+)([0-9-]+).*iNumber=([0-9]+).*cCodeOper=([0-9]+).*href="#">([^<]+)()()().*">([0-9-\ ,]+)\ [A-Z]+([0-9-\ ,]+)\ ([A-Z]+)\n')
# magiczny regexp po 2009.11
sz_trans1 = re.compile('_0_0">([0-9-]+)([0-9-]+)<.*MCheckBox_[0-9]+_1_([0-9]+)" />().*href="#">([^<]+)([^<]+)([^<]+)([^<]+).*">([0-9-\ ,]+)\ [A-Z]+.*">([0-9-\ ,]+)\ ([A-Z]+)\n')
sz_trans2 = re.compile('_0_0">([0-9-]+)([0-9-]+)<.*MCheckBox_[0-9]+_1_([0-9]+)" />().*href="#">([^<]+)([^<]+)([^<]+)()([0-9-\ ,]+)\ [A-Z]+.*">([0-9-\ ,]+)\ ([A-Z]+)\n')
sz_trans3 = re.compile('_0_0">([0-9-]+)([0-9-]+)<.*MCheckBox_[0-9]+_1_([0-9]+)" />().*href="#">([^<]+)([^<]+)()()([0-9-\ ,]+)\ [A-Z]+.*">([0-9-\ ,]+)\ ([A-Z]+)\n')
sz_next = re.compile('button\ id="PrevPage"\ onclick="doSubmit\(\'\',\'\',\'\',\'(.*)\',true,false,true,null\);return false"\ class="button">Poprzednie')
# przejscie do konta
submit = []
for form in br.forms():
for forma in form.controls:
submit.append((forma.name, forma.value))
submit[0] = ('__PARAMETERS', value)
none = None, ''
while submit.count(none)>0:
submit.remove(none)
submitstr = urlencode(submit) # zbieranie danych do POST
br.open("https://www.mbank.com.pl/account_oper_list.aspx", submitstr)
# strona z kontem, teraz istnieje mozliwosc filtrowania operacji
br.select_form(name="MainForm")
# br["daterange_from_day"] = '21'
# br["daterange_from_month"] = '11'
# br["daterange_from_year"] = '2009'
# br["daterange_to_day"] = '5'
# br["daterange_to_month"] = '12'
# br["daterange_to_year"] = '2009'
br["lastdays_period"] = [str(wybor_period)]
br["lastdays_days"] = str(wybor_numer)
br["accoperlist_typefilter_group"] = [str(wybor_typ)]
response_get = br.submit()
# zbieranie danych do klikniecia guzika Poprzednie operacje
strona = ''
stronatmp = response_get.read()
while sz_next.findall(stronatmp).__len__() == 1:
strona = strona+stronatmp
submit = []
for form in br.forms():
for forma in form.controls:
submit.append((forma.name, forma.value))
trans_next = sz_next.findall(stronatmp)
submit.pop(0) # bezpieczniejsze jest remove (('__PARAMETERS', '')) ale wtedy potrzeba try
submit[0] = ('__PARAMETERS', trans_next) # niby trans_next[0] bedzie poprawniej, ale tak tez dziala :D
while submit.count(none)>0:
submit.remove(none)
submitstr = urlencode(submit) # zbieranie danych do POST
submitstr = re.sub(r'\%5B|\%5D|\%27|\&account[^=]+=', '', submitstr)
response_get = br.open("https://www.mbank.com.pl/account_oper_list.aspx?",submitstr)
stronatmp = response_get.read()
###
strona = strona+stronatmp
strona = strona.decode('iso8859-2')
# print strona
strona = re.sub(r'\|', '', strona)
strona = re.sub(r'||', '\n', strona)
# print strona
r_trans = []
for trans_html in sz_grep.findall(strona):
trans_temp = sz_trans1.findall(strip_dspace(trans_html))
if trans_temp.__len__() == 0:
trans_temp = sz_trans2.findall(trans_html)
if trans_temp.__len__() == 0:
trans_temp = sz_trans3.findall(trans_html)
if trans_temp.__len__() == 1: # and re.match(valuea, str(trans_temp[0][3])):
trans_temp = list(trans_temp[0])
trans_temp[8] = strip_space(trans_temp[8])
trans_temp[9] = strip_space(trans_temp[9])
r_trans.append(trans_temp)
#if trans_temp.__len__() == 0:
#print "Rodzaj nieznany"+trans_html
return r_trans