Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
    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
Beispiel #4
0
 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
Beispiel #5
0
    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
Beispiel #6
0
 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