Beispiel #1
0
import pygsheets
from cache_request import CacheRequest
from os import path
from dateutil import parser
from pprint import pprint
from pynubank import Nubank
from datetime import datetime

cache = CacheRequest('get_account_feed')

if cache.has_cache():
    feed = cache.read_cache()
else:
    credentials = json.load(open('nubank_credentials.json'))
    nu = Nubank(credentials['cpf'], credentials['password'])
    feed = nu.get_account_feed()
    cache.save_cache(feed)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
#client = pygsheets.authorize(service_file='client_secret.json')
#nubank = client.open("Nubank")

#rows = []
#pprint(list(set(entry['category'] for entry in feed['events'])))

#bills = list(filter(lambda x: x['category'] in ('transactions') , feed['events']))

#sheets  = []
#rows = []
pprint(feed)
sys.exit(0)
Beispiel #2
0
# used to test from a json file with the statements
if test_file == "":
    if cpf == "" or pwd == "":
        print("missing cpf and/or password")
        raise SystemExit()

    uuid, qr_code = nu.get_qr_code()
    qr_code.print_ascii(invert=True)
    input('scan and press enter...')
    nu.authenticate_with_qr_code(os.environ['NU_CPF'], os.environ['NU_PWD'],
                                 uuid)

    balance = nu.get_account_balance()
    statements = list(
        filter(lambda x: x['__typename'] in PAYMENT_EVENT_TYPES,
               nu.get_account_feed()))
else:
    with open(test_file) as json_file:
        statements = json.load(json_file)
        balance = 1233.11

print(
    f'creating 90-day OFX file of account with balance {balance} at {target}...'
)

# here begins the uglyness
# I'm extremely regretful right now
ofx = ET.Element("OFX")

signonmsgsrsv1 = ET.SubElement(ofx, "SIGNONMSGSRSV1")
sonrs = ET.SubElement(signonmsgsrsv1, "SONRS")
Beispiel #3
0
        transaction["amount"] = '{:.2f}'.format(transaction['amount']).replace(
            '.', ',')
    return transaction.values()


if __name__ == '__main__':
    log_config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   'logging.json')
    setup_logging(log_config_file)

    logging.info('Initializen Nubank export')

    nu = Nubank()
    nu.authenticate_with_refresh_token(NUBANK_TOKEN, NUBANK_CERT)

    account_transactions = nu.get_account_feed()
    logging.info(f'Found {len(account_transactions)} account transactions')

    with open('export.csv', mode='w', encoding='utf-8') as tfile:
        fieldnames = [
            'id', '__typename', 'title', 'detail', 'postDate', 'amount',
            'originAccount', 'destinationAccount'
        ]
        writer = csv.DictWriter(tfile,
                                delimiter=';',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL,
                                fieldnames=fieldnames)

        data = list(map(lambda t: clean(t), account_transactions))
        writer.writeheader()