Git Product home page Git Product logo

Comments (5)

andreroggeri avatar andreroggeri commented on September 14, 2024

Se você entrar no site do nubank você vê as suas transações daquele cartão?
Consegue postar um exemplo de como você está buscando as transações?

from pynubank.

anhaabaete avatar anhaabaete commented on September 14, 2024

No app eu vejo, mas o porém é que preciso saber qual cartão. Acho que ao cancelar eles apagam a informação. Não sei...

O código a baixo:

#!/bin/python3

from pynubank import Nubank
nu = Nubank()
import json
import os
from meu_googlesheet import googlesheet
import sys


########################
# Dados gerais da fatura
########################
mesabertura = ''
mesfechamento = ''

if len(sys.argv) > 2:
    mesabertura = sys.argv[1]
    mesfechamento = sys.argv[2]
else:
    print("falta argumentos: meunu.py [inicio] [fim]")
    exit(0)


hereiam = os.path.expanduser( '~' ) + "/code/meunu"


print("Auntenticando...")
nu.authenticate_with_cert('xxxxxxxx', 'xxxxxxxxx', hereiam+'/cert.p12')




jsonstr=""
bills=[]




print("get_bills...")
bills = nu.get_bills()
bills = [x for x in bills if x["summary"]["open_date"][:7] == mesabertura 
                                and x["summary"]["close_date"][:7] == mesfechamento]

summary = bills[0]["summary"]
abertura = summary["open_date"]
fechamento = summary["close_date"]

#######################
# Registros de compras desabilitado, bills já contem compras (com menos detalhes)
#######################
#card_statements = nu.get_card_statements()

#card_statements = [x for x in card_statements if x["time"][:10] >= summary["open_date"] 
 #                                                   and x["time"][:10] <= summary["close_date"]]


#file = open('lancamento_cartao.json', 'w')
#file.write(json.dumps(card_statements, indent=2))
#file.close()



##############
# Pagamentos
##############
print("get_bill_details...")
bill_details = nu.get_bill_details(bills[0])
r = len(bill_details['bill']['line_items'])
for i in range(r):
    percentagem = str(int((i / r) * 100));
    print(percentagem + "% ", end="\r")
    momentbill = bill_details['bill']['line_items'][i]


    file = open(hereiam+'/dump.json', 'w')
    file.write(json.dumps(momentbill, indent=2))
    file.close()
    if momentbill.get('category')!='Pagamento' and momentbill.get("type")!='payment':
        if momentbill.get("href"):
            idbill = momentbill.get("href").replace('nuapp://transaction/','https://prod-s1-facade.nubank.com.br/api/transactions/')
        else:
            idbill = 'https://prod-s1-facade.nubank.com.br/api/transactions/' + momentbill.get("loan_id")
    
        momentbill["_links"] = {"self": {
            "href": idbill
        }}
        try:
            bill_more_detail=nu.get_card_statement_details(momentbill)
            momentbill["card_last_four_digits"] = bill_more_detail['transaction'].get('card_last_four_digits')
        except:
            print(momentbill)
            
        
        
        

print("Fineshed                          ")

file = open(hereiam+'/bills.json', 'w')
file.write(json.dumps(bill_details, indent=2))
file.close()


creditonu = nu.get_credit_card_balance()
creditonu = creditonu['available']/100

## Atualiza Folha de Calculo ###
print("Atualizando Folha de Calculo...")
googlesheet(abertura,fechamento,hereiam,creditonu)

Mais especificamente neste trecho:

file = open(hereiam+'/dump.json', 'w')
    file.write(json.dumps(momentbill, indent=2))
    file.close()
    if momentbill.get('category')!='Pagamento' and momentbill.get("type")!='payment':
        if momentbill.get("href"):
            idbill = momentbill.get("href").replace('nuapp://transaction/','https://prod-s1-facade.nubank.com.br/api/transactions/')
        else:
            idbill = 'https://prod-s1-facade.nubank.com.br/api/transactions/' + momentbill.get("loan_id")
    
        momentbill["_links"] = {"self": {
            "href": idbill
        }}
        try:
            bill_more_detail=nu.get_card_statement_details(momentbill)
            momentbill["card_last_four_digits"] = bill_more_detail['transaction'].get('card_last_four_digits')
        except:
            print(momentbill)
            ```
            
            

from pynubank.

anhaabaete avatar anhaabaete commented on September 14, 2024

Talvez meu código esteja antigo ou sujo devido a ter feito a muito tempo, e ser apenas para minhas próprias contas. Eu só preciso do valor e do número cartão que fez a compra.

from pynubank.

andreroggeri avatar andreroggeri commented on September 14, 2024

Eu fiz um teste aqui e consegui recuperar os 4 ultimos digitos:

nu = Nubank()
nu.authenticate_with_cert(...)

transactions = nu.get_card_statements()

transaction = transactions[0]

details = nu.get_card_statement_details(transaction)

print(f'card_last_four_digits={details["transaction"]["card_last_four_digits"]}')

from pynubank.

anhaabaete avatar anhaabaete commented on September 14, 2024
nu = Nubank()
nu.authenticate_with_cert(...)

transactions = nu.get_card_statements()

transaction = transactions[0]

details = nu.get_card_statement_details(transaction)

print(f'card_last_four_digits={details["transaction"]["card_last_four_digits"]}')

Agradeço Imensamente o código resumido.
Mas acho que eles tiram a referencia mesmo porque aparece isso:

Auntenticando...
Traceback (most recent call last):
  File "/home/tneves/code/meunu/a.py", line 14, in <module>
    details = nu.get_card_statement_details(transaction)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tneves/.local/lib/python3.12/site-packages/pynubank/auth_mode.py", line 23, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tneves/.local/lib/python3.12/site-packages/pynubank/nubank.py", line 202, in get_card_statement_details
    return self._client.get(statement['_links']['self']['href'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tneves/.local/lib/python3.12/site-packages/pynubank/utils/http.py", line 46, in get
    return self._handle_response(self.raw_get(url))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tneves/.local/lib/python3.12/site-packages/pynubank/utils/http.py", line 35, in _handle_response
    raise NuRequestException(response)
pynubank.exception.NuRequestException: The request made failed with HTTP status code 400

Como se não existisse a referência.
Será que perde-se mesmo?

from pynubank.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.