Ejemplo n.º 1
0
def export():

    t_db = db.init_db()
    if not t_db:
        print('Error initialising database')
        return

    creds = get_credentials()
    if not creds:
        return

    br = login(creds)
    if not br:
        return

    br = open_transactions_page(br)
    if not br:
        return

    trans = []

    while True:
        text = br.response().read()

        q = PyQuery(text)

        page_trans = fetchTransactions(text)
        trans += page_trans

        nextButton = q('a[name="nextButton"]')
        isNextVisible = len(nextButton) != 0
        if not isNextVisible:
            break

        page_count = len(page_trans)
        print('Got %s transactions, from %s to %s' % (page_count,
                                                      page_trans[0].date,
                                                      page_trans[-1].date))
        print('Opening next page...')
        br.open(nextButton[0].attrib['href'])

        #if len(trans) > 50:
        #    break

    new_trans = db.get_only_new_transactions(trans)
    print('Total of %s new transactions obtained' % len(new_trans))

    if len(new_trans) != 0:
        print('Saving transactions...')
        db.save_transactions(new_trans)

        write_qif(new_trans)
        write_csv(new_trans)
Ejemplo n.º 2
0
def export(csv, statements):

    if not os.path.exists(export_path):
        os.makedirs(export_path)

    t_db = db.init_db()
    if not t_db:
        print('Error initialising database')
        return

    creds = get_credentials()
    if not creds:
        return

    br = login(creds)
    if not br:
        return

    text = br.response().read()
    #log_file('login.html', text)

    br = open_transactions_page(br)
    if not br:
        return

    trans = []

    i = 1
    while True:
        text = br.response().read()

        #log_file('step%s.html' % i, text)
        #i += 1

        q = PyQuery(text)

        page_trans = fetchTransactions(text)
        trans += page_trans

        nextButton = q('div[name="transactionsPagingLinks"] a[name="nextButton"]')
        isNextVisible = len(nextButton) != 0
        if not isNextVisible:
            break

        page_count = len(page_trans)
        if page_count == 0:
            break;

        print('Got %s transactions, from %s to %s' % (page_count,
                                                      format_tran_date_for_qif(page_trans[0].date),
                                                      format_tran_date_for_qif(page_trans[-1].date)))
        print('Opening next page...')

        next_url = nextButton[0].attrib['href']
        br.open(next_url)

        #if len(trans) > 60:
        #    break

    new_trans = db.get_only_new_transactions(trans)
    print('Total of %s new transactions obtained' % len(new_trans))

    if len(new_trans) != 0:

        print('Saving transactions...')
        db.save_transactions(new_trans)

        s_d = reduce(lambda t1, t2: t1 if t1.date < t2.date else t2, new_trans).date
        e_d = reduce(lambda t1, t2: t1 if t1.date > t2.date else t2, new_trans).date

        if csv:
            file_name = get_file_name(export_path, s_d, e_d, 'csv')
            write_csv(new_trans, file_name)
        else:
            file_name = get_file_name(export_path, s_d, e_d, 'qif')
            write_qif(new_trans, file_name)

    if statements:
        br = open_statements_page(br)
        if not br:
            return

        text = br.response().read()
        q = PyQuery(text)

        for row in q('a[class="s_downloads"]'):
            statement_date = datetime.strptime(row.text, '%d %b %Y').strftime('%Y-%m-%d')
            statement_name = '28 Degrees Statement ' + statement_date + '.pdf'
            statement_path = os.path.join(export_path, statement_name)

            if not os.path.exists(statement_path):
                print('Retrieving statement ' + row.text + ' and saving to ' + statement_path)
                br.retrieve(row.attrib['href'], statement_path)
Ejemplo n.º 3
0
def export(csv, statements):

    if not os.path.exists(export_path):
        os.makedirs(export_path)

    t_db = db.init_db()
    if not t_db:
        print('Error initialising database')
        return

    creds = get_credentials()
    if not creds:
        return

    br = login(creds)
    if not br:
        return

    text = br.response().read()
    qq = PyQuery(text)
    statLink = qq('li[id="cardsonline.statements"] a')
    #log_file('login.html', text)

    br = open_transactions_page(br)
    if not br:
        return

    trans = []

    i = 1
    while True:
        text = br.response().read()

        #log_file('step%s.html' % i, text)
        #i += 1

        q = PyQuery(text)

        page_trans = fetchTransactions(text)
        trans += page_trans

        nextButton = q(
            'div[name="transactionsPagingLinks"] a[name="nextButton"]')
        isNextVisible = len(nextButton) != 0
        if not isNextVisible:
            break

        page_count = len(page_trans)
        if page_count == 0:
            break

        print('Got %s transactions, from %s to %s' %
              (page_count, format_tran_date_for_qif(page_trans[0].date),
               format_tran_date_for_qif(page_trans[-1].date)))
        print('Opening next page...')

        next_url = nextButton[0].attrib['href']
        br.open(next_url)

        #if len(trans) > 60:
        #    break

    new_trans = db.get_only_new_transactions(trans)
    print('Total of %s new transactions obtained' % len(new_trans))

    if len(new_trans) != 0:

        print('Saving transactions...')
        db.save_transactions(new_trans)

        s_d = reduce(lambda t1, t2: t1
                     if t1.date < t2.date else t2, new_trans).date
        e_d = reduce(lambda t1, t2: t1
                     if t1.date > t2.date else t2, new_trans).date

        if csv:
            file_name = get_file_name(export_path, s_d, e_d, 'csv')
            write_csv(new_trans, file_name)
        else:
            file_name = get_file_name(export_path, s_d, e_d, 'qif')
            write_qif(new_trans, file_name)

    if statements:

        if len(statLink) == 0:
            print('Unable to find link to statements page')
            return

        br.open(statLink[0].attrib['href'])
        text = br.response().read()
        q = PyQuery(text)

        for row in q('a[class="s_downloads"]'):
            statement_date = datetime.strptime(row.text,
                                               '%d %b %Y').strftime('%Y-%m-%d')
            statement_name = '28 Degrees Statement ' + statement_date + '.pdf'
            statement_path = os.path.join(export_path, statement_name)

            if not os.path.exists(statement_path):
                print('Retrieving statement ' + row.text + ' and saving to ' +
                      statement_path)
                br.retrieve(row.attrib['href'], statement_path)
Ejemplo n.º 4
0
def export(csv):

    if not os.path.exists(export_path):
        os.makedirs(export_path)

    t_db = db.init_db()
    if not t_db:
        print('Error initialising database')
        return

    creds = get_credentials()
    if not creds:
        return

    br = login(creds)
    if not br:
        return

    br = open_transactions_page(br)
    if not br:
        return

    trans = []

    #i = 1
    while True:
        text = br.response().read()

        #with open('step%s.html' % i, 'w') as f:
        #    f.write(text)
        #i += 1

        q = PyQuery(text)

        page_trans = fetchTransactions(text)
        trans += page_trans

        nextButton = q('div[name="transactionsPagingLinks"] a[name="nextButton"]')
        isNextVisible = len(nextButton) != 0
        if not isNextVisible:
            break

        page_count = len(page_trans)
        print('Got %s transactions, from %s to %s' % (page_count,
                                                      page_trans[0].date,
                                                      page_trans[-1].date))
        print('Opening next page...')

        next_url = nextButton[0].attrib['href']
        br.open(next_url)

        #if len(trans) > 60:
        #    break

    new_trans = db.get_only_new_transactions(trans)
    print('Total of %s new transactions obtained' % len(new_trans))

    if len(new_trans) != 0:

        print('Saving transactions...')
        db.save_transactions(new_trans)

        f_str = '%d/%m/%Y'
        s_d = datetime.strptime(reduce(lambda t1, t2: t1 if datetime.strptime(t1.date, f_str) <
                                                      datetime.strptime(t2.date, f_str) else t2,
                                       new_trans).date, f_str)
        e_d = datetime.strptime(reduce(lambda t1, t2: t1 if datetime.strptime(t1.date, f_str) >
                                                      datetime.strptime(t2.date, f_str) else t2,
                                       new_trans).date, f_str)
        out_str = '%Y.%m.%d'

        if csv:
            file_name = os.path.join(export_path, '%s-%s.csv' % (s_d.strftime(out_str), e_d.strftime(out_str)))
            write_csv(new_trans, file_name)
        else:
            file_name = os.path.join(export_path, '%s-%s.qif' % (s_d.strftime(out_str), e_d.strftime(out_str)))
            write_qif(new_trans, file_name)
Ejemplo n.º 5
0
        print('Got %s transactions, from %s to %s' %
              (page_count, format_tran_date_for_qif(page_trans[0].date),
               format_tran_date_for_qif(page_trans[-1].date)))
        print('Opening next page...')

        try:
            nextButton = get_next_btn(driver)
            if not nextButton.is_displayed():
                break
            nextButton.click()
            time.sleep(WAIT_DELAY)
        except NoSuchElementException, err:
            break

    new_trans = db.get_only_new_transactions(trans)
    print('Total of %s new transactions obtained' % len(new_trans))

    if len(new_trans) != 0:

        print('Saving transactions...')
        db.save_transactions(new_trans)

        s_d = reduce(lambda t1, t2: t1
                     if t1.date < t2.date else t2, new_trans).date
        e_d = reduce(lambda t1, t2: t1
                     if t1.date > t2.date else t2, new_trans).date

        if csv:
            file_name = get_file_name(export_path, s_d, e_d, 'csv')
            write_csv(new_trans, file_name)