def parse(self): with open(self.filename, "r", newline="") as csvfile: reader = csv.reader(csvfile, dialect=tsv) header = True for row in reader: if header: if len(row) > 1 and row[0].startswith("Účet"): header = False continue if len(row) < 24: continue acc, price, currency, date, date2, bank_code, bank_name, bank_name2, account, detail_from, add1, add2, add3, tr_type, detail1, detail2, detail3, detail4, detail5, ks, vs, ss, pay_title, ref_num = row[ 0:24 ] payment = Payment() payment.price = float(price.replace(",", ".")) payment.date = datetime.datetime.strptime(date, "%Y-%m-%d") payment.account = (account + "/" + bank_code).strip("/") payment.account_from = acc + "/" + UCB_BANK_CODE payment.detail_from = detail_from payment.transaction_type = dict(self.TYPE_MAP).get(tr_type, PaymentType.TYPE_UNDEFINED) if payment.transaction_type == PaymentType.TYPE_UNDEFINED: if tr_type.lower().startswith("poplat"): payment.transaction_type = PaymentType.TYPE_FEES else: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment.message = tr_type if payment.transaction_type == PaymentType.TYPE_CARD: payment.place = detail5 payment.description = ("%s %s %s" % (detail1, detail2, detail3)).strip() payment.vs = vs payment.ks = ks payment.ss = ss yield payment
def parse(self): messages = self.downloader.download('UNSEEN HEADER Subject "Info 24"') for num, message in messages: date = self._get_message_date(message) subject = self._get_subject(message) if 'Avízo' in subject: body = self._get_message_content(message) body = body[0:body.index(':::::::::::::')] payment = Payment() payment.date = date if 'klientko' in body: body = '\n'.join(body.split('\n\n')[1:]) detail = False account_num_regex = re.compile(r'[^\d]+((\d+\-)?\d+/\d+)$') sender_message = False transaction_type = '' for line in body.split('\n'): account_number_matches = account_num_regex.match(line) if 'Zůstatek na účtu' in line: yield payment payment = Payment() payment.date = date detail = False sender_message = False elif line.startswith('dne'): transaction_type = ' '.join(line.split(' ')[7:])[0:-1] elif line.startswith('částka'): payment.price = float( line.split(' ')[1].replace(',', '.')) elif account_number_matches: payment.account = account_number_matches.group(1) elif line.startswith('detail'): detail = True elif detail: if not line.startswith( 'splatnost') and not line.startswith( 'zpr') and 'SPO' not in line: payment.detail_from = line if 'SPO' in line: payment.description = line detail = False elif line.startswith('KS'): payment.ks = line.split(' ')[1] elif line.startswith('VS'): payment.vs = line.split(' ')[-1].lstrip('0') elif line.startswith('SS'): payment.ss = line.split(' ')[1] elif line.startswith('zpráva pro'): sender_message = True elif sender_message: payment.message = line sender_message = False elif line.startswith('Od'): payment.detail_from = " ".join(line.split(' ')[1:]) elif line.startswith('Místo'): payment.place = " ".join(line.split(' ')[1:]) elif 'úrok' in line: transaction_type = self.TYPE_SAVING payment.transaction_type = dict(self.TYPES_MAP).get( transaction_type, PaymentType.TYPE_UNDEFINED)
def parse(self): with open(self.filename, 'r', newline='') as csvfile: reader = csv.reader(csvfile, dialect=tsv) header = True for row in reader: if header: if len(row) > 1 and row[0].startswith('Účet'): header = False continue if len(row) < 24: continue acc, price, currency, date, date2, bank_code, bank_name, bank_name2, account, detail_from, add1, add2, add3, \ tr_type, detail1, detail2, detail3, detail4, detail5, ks, vs, ss, pay_title, ref_num = row[0:24] payment = Payment() payment.price = float(price.replace(',', '.')) payment.date = datetime.datetime.strptime(date, '%Y-%m-%d') payment.account = (account + '/' + bank_code).strip('/') payment.account_from = acc + '/' + UCB_BANK_CODE payment.detail_from = detail_from payment.transaction_type = dict(self.TYPE_MAP).get( tr_type, PaymentType.TYPE_UNDEFINED) if payment.transaction_type == PaymentType.TYPE_UNDEFINED: if tr_type.lower().startswith('poplat'): payment.transaction_type = PaymentType.TYPE_FEES else: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment.message = tr_type if payment.transaction_type == PaymentType.TYPE_CARD: payment.place = detail5 payment.description = ('%s %s %s' % (detail1, detail2, detail3)).strip() payment.vs = vs payment.ks = ks payment.ss = ss yield payment
def parse(self): messages = self.downloader.download('UNSEEN HEADER Subject "Info 24"') for num, message in messages: date = self._get_message_date(message) subject = self._get_subject(message) if "Avízo" in subject: body = self._get_message_content(message) body = body[0 : body.index(":::::::::::::")] payment = Payment() payment.date = date if "klientko" in body: body = "\n".join(body.split("\n\n")[1:]) detail = False account_num_regex = re.compile(r"[^\d]+((\d+\-)?\d+/\d+)$") sender_message = False transaction_type = "" for line in body.split("\n"): account_number_matches = account_num_regex.match(line) if "Zůstatek na účtu" in line: yield payment payment = Payment() payment.date = date detail = False sender_message = False elif line.startswith("dne"): transaction_type = " ".join(line.split(" ")[7:])[0:-1] elif line.startswith("částka"): payment.price = float(line.split(" ")[1].replace(",", ".")) elif account_number_matches: payment.account = account_number_matches.group(1) elif line.startswith("detail"): detail = True elif detail: if not line.startswith("splatnost") and not line.startswith("zpr") and "SPO" not in line: payment.detail_from = line if "SPO" in line: payment.description = line detail = False elif line.startswith("KS"): payment.ks = line.split(" ")[1] elif line.startswith("VS"): payment.vs = line.split(" ")[-1].lstrip("0") elif line.startswith("SS"): payment.ss = line.split(" ")[1] elif line.startswith("zpráva pro"): sender_message = True elif sender_message: payment.message = line sender_message = False elif line.startswith("Od"): payment.detail_from = " ".join(line.split(" ")[1:]) elif line.startswith("Místo"): payment.place = " ".join(line.split(" ")[1:]) elif "úrok" in line: transaction_type = self.TYPE_SAVING payment.transaction_type = dict(self.TYPES_MAP).get(transaction_type, PaymentType.TYPE_UNDEFINED)
def parse(self): messages = self.downloader.download( 'UNSEEN HEADER From "*****@*****.**"') for num, message in messages: if 'o zůstatku' not in self._get_subject(message): self.downloader.set_unseen(num) body = self._get_message_content(message) payment = Payment() for line in body.split('\n'): if 'Vás informuje' in line: payment.account_from = ''.join(''.join(line.split(':')[1]).strip().split(' ')[0]) + \ '/' + UCB_BANK_CODE elif line.startswith('Číslo účtu protistrany:'): payment.account = self._get_line_data(line).lstrip( '0/') or None elif line.startswith('Název účtu protistrany:'): payment.detail_from = self._get_line_data(line) or None elif line.startswith('Částka:'): payment.price = float(''.join( self._get_line_data(line).split(' ')[0]).replace( '.', '').replace(',', '.')) elif line.startswith('Konstatní symbol:'): payment.ks = self._get_line_data(line) or None elif line.startswith('Variabilní symbol:'): payment.vs = self._get_line_data(line) or None elif line.startswith('Specifický symbol:'): payment.ss = self._get_line_data(line) or None elif line.startswith('Datum:'): try: payment.date = datetime.datetime.strptime( self._get_line_data(line), '%d.%m.%Y %H:%M') except ValueError as e: payment.date = self._get_message_date(message) elif line.startswith('Detaily transakce:'): line_content = self._get_line_data(line) details = line_content.split(' ') if len(details) == 5: payment.place = details[4].strip() payment.description = ' '.join( [x.strip() for x in details[0:3]]) elif len(details) > 0: payment.description = ' '.join(details) or None else: payment.message = line_content or None yield payment
def parse(self): messages = self.downloader.download('UNSEEN HEADER From "*****@*****.**"') for num, message in messages: body = self._get_message_content(message) payment = Payment() payment_type = 0 for line in body.split('\n'): if 'ODCHOZI' in line: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment_type = self.TYPE_OUTGOING elif 'PRICHOZI' in line: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment_type = self.TYPE_INCOMING elif (line.startswith('Z:') and payment_type == self.TYPE_INCOMING) or ( line.startswith('Na') and payment_type == self.TYPE_OUTGOING): payment.account = '/'.join( self._get_line_data(line).split('/')[0:2]) elif (line.startswith('Z:') and payment_type == self.TYPE_OUTGOING) or ( line.startswith('Na') and payment_type == self.TYPE_INCOMING): payment.account_from = '/'.join( self._get_line_data(line).split('/')[0:2]) elif line.startswith('Castka:'): payment.price = float(''.join( self._get_line_data(line).split(' ')[0:-1]).replace( ',', '.')) if payment_type == self.TYPE_OUTGOING: payment.price = -1 * payment.price elif line.startswith('KS:'): payment.ks = self._get_line_data(line) elif line.startswith('VS:'): payment.vs = self._get_line_data(line) elif line.startswith('SS:'): payment.ss = self._get_line_data(line) elif line.startswith('Dne:'): try: payment.date = datetime.datetime.strptime( self._get_line_data(line), '%d.%m.%Y %H:%M') except ValueError as e: payment.date = self._get_message_date(message) elif line.startswith('Zprava:'): payment.message = self._get_line_data(line) yield payment
def parse(self): messages = self.downloader.download('UNSEEN HEADER From "*****@*****.**"') for num, message in messages: if "o zůstatku" not in self._get_subject(message): self.downloader.set_unseen(num) body = self._get_message_content(message) payment = Payment() for line in body.split("\n"): if "Vás informuje" in line: payment.account_from = ( "".join("".join(line.split(":")[1]).strip().split(" ")[0]) + "/" + UCB_BANK_CODE ) elif line.startswith("Číslo účtu protistrany:"): payment.account = self._get_line_data(line).lstrip("0/") or None elif line.startswith("Název účtu protistrany:"): payment.detail_from = self._get_line_data(line) or None elif line.startswith("Částka:"): payment.price = float( "".join(self._get_line_data(line).split(" ")[0]).replace(".", "").replace(",", ".") ) elif line.startswith("Konstatní symbol:"): payment.ks = self._get_line_data(line) or None elif line.startswith("Variabilní symbol:"): payment.vs = self._get_line_data(line) or None elif line.startswith("Specifický symbol:"): payment.ss = self._get_line_data(line) or None elif line.startswith("Datum:"): try: payment.date = datetime.datetime.strptime(self._get_line_data(line), "%d.%m.%Y %H:%M") except ValueError as e: payment.date = self._get_message_date(message) elif line.startswith("Detaily transakce:"): line_content = self._get_line_data(line) details = line_content.split(" ") if len(details) == 5: payment.place = details[4].strip() payment.description = " ".join([x.strip() for x in details[0:3]]) elif len(details) > 0: payment.description = " ".join(details) or None else: payment.message = line_content or None yield payment
def parse(self): messages = self.downloader.download('UNSEEN HEADER From "*****@*****.**"') for num, message in messages: body = self._get_message_content(message) payment = Payment() payment_type = 0 for line in body.split("\n"): if "ODCHOZI" in line: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment_type = self.TYPE_OUTGOING elif "PRICHOZI" in line: payment.transaction_type = PaymentType.TYPE_TRANSACTION payment_type = self.TYPE_INCOMING elif (line.startswith("Z:") and payment_type == self.TYPE_INCOMING) or ( line.startswith("Na") and payment_type == self.TYPE_OUTGOING ): payment.account = "/".join(self._get_line_data(line).split("/")[0:2]) elif (line.startswith("Z:") and payment_type == self.TYPE_OUTGOING) or ( line.startswith("Na") and payment_type == self.TYPE_INCOMING ): payment.account_from = "/".join(self._get_line_data(line).split("/")[0:2]) elif line.startswith("Castka:"): payment.price = float("".join(self._get_line_data(line).split(" ")[0:-1]).replace(",", ".")) if payment_type == self.TYPE_OUTGOING: payment.price = -1 * payment.price elif line.startswith("KS:"): payment.ks = self._get_line_data(line) elif line.startswith("VS:"): payment.vs = self._get_line_data(line) elif line.startswith("SS:"): payment.ss = self._get_line_data(line) elif line.startswith("Dne:"): try: payment.date = datetime.datetime.strptime(self._get_line_data(line), "%d.%m.%Y %H:%M") except ValueError as e: payment.date = self._get_message_date(message) elif line.startswith("Zprava:"): payment.message = self._get_line_data(line) yield payment