def parse(self): with open(self.filename, 'r', newline='', encoding='iso-8859-2') as csvfile: reader = csv.reader(csvfile, dialect=tsv) header = True for row in reader: if header: if len(row) > 1 and row[0].startswith('#Datum'): header = False continue if len(row) < 11: continue date, date2, tr_type, description, from_name, contra_account, ks, vs, ss, price, balance = row[ 0:11] payment = Payment() payment.price = float(price.replace(',', '.').replace(' ', '')) payment.date = datetime.datetime.strptime(date, '%d-%m-%Y') description = description.strip(' \'') from_name = from_name.strip(' \'') contra_account = contra_account.strip(' \'') if ' ' in description: description = description.split( ' ')[0] if '/' in description: parts = description.split('/') from_name = '/'.join(parts[0:-1]) payment.place = parts[-1].strip() description = '' payment.description = description.strip() payment.detail_from = from_name payment.account = contra_account.lstrip('0').lstrip( '-').lstrip('0') payment.transaction_type = dict(self.TYPE_MAP).get( tr_type, PaymentType.TYPE_UNDEFINED) yield payment
def parse(self): with open(self.filename, "r", newline="", encoding="iso-8859-2") as csvfile: reader = csv.reader(csvfile, dialect=tsv) header = True for row in reader: if header: if len(row) > 1 and row[0].startswith("#Datum"): header = False continue if len(row) < 11: continue date, date2, tr_type, description, from_name, contra_account, ks, vs, ss, price, balance = row[0:11] payment = Payment() payment.price = float(price.replace(",", ".").replace(" ", "")) payment.date = datetime.datetime.strptime(date, "%d-%m-%Y") description = description.strip(" '") from_name = from_name.strip(" '") contra_account = contra_account.strip(" '") if " " in description: description = description.split(" ")[0] if "/" in description: parts = description.split("/") from_name = "/".join(parts[0:-1]) payment.place = parts[-1].strip() description = "" payment.description = description.strip() payment.detail_from = from_name payment.account = contra_account.lstrip("0").lstrip("-").lstrip("0") payment.transaction_type = dict(self.TYPE_MAP).get(tr_type, PaymentType.TYPE_UNDEFINED) yield payment
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: header = False continue my_account_num, iban, contra_account, name, date1, date2, price, detail, description, category, code = row payment = Payment() payment.price = float(price.replace(',', '.')) payment.detail_from = name.strip('.').strip() or None payment.date = datetime.datetime.strptime(date1, '%d.%m.%Y') payment.description = description or category payment.transaction_type = dict(self.TYPE_MAP).get( detail, PaymentType.TYPE_UNDEFINED) if payment.transaction_type != PaymentType.TYPE_CARD: payment.account = contra_account yield payment
def parse(self): with open(self.filename, 'r', newline='') as csvfile: reader = csv.reader(csvfile) header = True for row in reader: if header: header = False continue date, tr_type, acc_name, contra_account, contra_account_code, description, price = row[ 0:7] payment = Payment() payment.price = float(price.replace(',', '.').replace(' ', '')) payment.date = datetime.datetime.strptime(date, '%d.%m.%Y') payment.message = description payment.description = description payment.account = (contra_account.lstrip('0') + '/' + contra_account_code).strip('/').strip() payment.transaction_type = dict(self.TYPE_MAP).get( tr_type, PaymentType.TYPE_UNDEFINED) yield payment
def parse(self): with open(self.filename, "r", newline="") as csvfile: reader = csv.reader(csvfile) header = True for row in reader: if header: header = False continue date, tr_type, acc_name, contra_account, contra_account_code, description, price = row[0:7] payment = Payment() payment.price = float(price.replace(",", ".").replace(" ", "")) payment.date = datetime.datetime.strptime(date, "%d.%m.%Y") payment.message = description payment.description = description payment.account = (contra_account.lstrip("0") + "/" + contra_account_code).strip("/").strip() payment.transaction_type = dict(self.TYPE_MAP).get(tr_type, PaymentType.TYPE_UNDEFINED) yield payment
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: header = False continue my_account_num, iban, contra_account, name, date1, date2, price, detail, description, category, code = ( row ) payment = Payment() payment.price = float(price.replace(",", ".")) payment.detail_from = name.strip(".").strip() or None payment.date = datetime.datetime.strptime(date1, "%d.%m.%Y") payment.description = description or category payment.transaction_type = dict(self.TYPE_MAP).get(detail, PaymentType.TYPE_UNDEFINED) if payment.transaction_type != PaymentType.TYPE_CARD: payment.account = contra_account 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('Vaše ČSOB')] 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 sender_name = False transaction_type = '' valid = True for line in body.split('\n'): account_number_matches = account_num_regex.match(line) if 'Zůstatek na účtu' in line: if valid: print(payment) yield payment payment = Payment() payment.date = date detail = False valid = True sender_message = False sender_name = False elif line.startswith('dne'): transaction_type = ' '.join(line.split(' ')[7:])[0:-1] detail = False sender_message = False sender_name = False payment = Payment() payment.date = date elif 'bude na' in line: valid = False elif line.lower().startswith('částka'): if ':' in line: line = "castka " + line.split(':')[1].strip() payment.price = float( line.split(' ')[1].replace(',', '.')) elif account_number_matches and 'účet' in line: payment.account = account_number_matches.group(1) elif line.lower().startswith( 'číslo účtu' ) and transaction_type != self.TYPE_FEE_FX: payment.account = line.split(':')[1].strip() elif line.startswith('detail') or line.startswith( 'Účel platby'): detail = True 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 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 if transaction_type == self.TYPE_TRANSACTION_ZPS: payment.description = line detail = False elif sender_name: payment.detail_from = line sender_name = False elif sender_message: payment.message = line sender_message = False elif line.startswith('Od'): payment.detail_from = " ".join(line.split(' ')[1:]) elif line.startswith('Plátce'): sender_name = True 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): 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): 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