def feed(self): doc = lxml.html.parse(self.__file) root = doc.getroot() txt1 = root.xpath(self.xpathAcctID) self.__statement.set_acct_id(txt1[0].text) txt1 = root.xpath(self.xpathServDate) debug_print(txt1) self.__statement.set_serv_date(format_trn_date(txt1[0].text)) self.__statement.set_start_date(format_trn_date(txt1[1].text[0:7])) self.__statement.set_end_date(format_trn_date(txt1[1].text[-7:])) txt2 = root.xpath('body/table[2]/tr[@class="rowTrnData"]') for tr in txt2: curTrans = BankTrans() curTrans.trnType = "CREDIT" curTrans.set_dates(opDate = tr[1].text, \ checkDate = tr[2].text, \ period = self.__statement.getPeriod()) curTrans.opNum = tr[3].text curTrans.opPayee = tr[4].text curTrans.opCur = tr[5].text if tr[6].text: curTrans.opSum = isCredit(tr[6].text) curTrans.accSum = isCredit(tr[7].text) self.__statement.insertTransaction(curTrans)
def get_statement_params(self, str): rx = '.*\s('+_long_date_fmt+')\s*-\s*('+_long_date_fmt+')\s*('+_long_date_fmt+').*' params_rx = re.compile(rx, re.L) result = params_rx.match(str) if result: print(result.groups()) self.__statement.set_start_date(format_trn_date(result.group(1))) self.__statement.set_end_date(format_trn_date(result.group(2))) self.__statement.set_serv_date(format_trn_date(result.group(3))) else: raise(Exception("non-header string in header position"))
def process_trans(self, str): result = prog.match(str) if result: fields = trans.match(str) assert fields print(fields.groups()) curTrans = BankTrans() curTrans.trnType = "CREDIT" curTrans.set_dates(opDate = format_trn_date(fields.group(1)), \ checkDate = format_trn_date(fields.group(2)), \ period = self.__statement.getPeriod()) curTrans.opNum = fields.group(3) curTrans.opPayee = fields.group(4).decode('cp1251') curTrans.opCur = fields.group(5) curTrans.opSum = fields.group(6) curTrans.accSum = isCredit(fields.group(7)) self.__statement.insertTransaction(curTrans) pass