Repository: andreroggeri/pynubank

Issue:
Erro em get_card_statements()
Ao tentar utilizar o método get_card_statements() é retornado o erro 

> Traceback (most recent call last):
  File "C:\Python\Python310\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Python\Python310\lib\site-packages\pynubank\auth_mode.py", line 23, in wrapper
    return function(*args, **kwargs)
  File "C:\Python\Python310\lib\site-packages\pynubank\nubank.py", line 199, in get_account_statements
    return list(filter(lambda x: x['__typename'] in PAYMENT_EVENT_TYPES, feed))
  File "C:\Python\Python310\lib\site-packages\pynubank\utils\parsing.py", line 28, in parse_pix_transaction
    transaction['amount'] = parse_float(transaction['detail'])
  File "C:\Python\Python310\lib\site-packages\pynubank\utils\parsing.py", line 19, in parse_float
    return float(re.search(r'(?:\d*\.)*\d+,\d{1,2}', value).group().replace('.', '').replace(',', '.'))
AttributeError: 'NoneType' object has no attribute 'group'

Em parsing.py na função parse_float(value: str), value recebe um valor de uma string  sem o valor em R$. Isto veio de uma entrada antiga que tive com os dizeres "Estorno - Transferência enviada pelo Pix". Talvez seja uma condição atípica e não esperada pelo código.

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/51127103/badge)](https://coveralls.io/builds/51127103)

Coverage decreased (-0.02%) to 99.37% when pulling **665f1377a489ba568a3c703663c301399dce771f on fix-pix-parsing** into **1817459911645eed3b4c94d6e42a115293e5c328 on main**.


Patch:
diff --git a/pynubank/utils/parsing.py b/pynubank/utils/parsing.py
index c1bed33..75d4317 100644
--- a/pynubank/utils/parsing.py
+++ b/pynubank/utils/parsing.py
@@ -1,5 +1,6 @@
 import re
 
+BRL = 'R$'
 TITLE_INFLOW_PIX = 'Transferência recebida'
 TITLE_OUTFLOW_PIX = 'Transferência enviada'
 TITLE_REVERSAL_PIX = 'Reembolso enviado'
@@ -23,7 +24,7 @@ def parse_pix_transaction(transaction: dict) -> dict:
     if transaction['__typename'] != 'GenericFeedEvent':
         return transaction
 
-    if transaction['title'] in PIX_TRANSACTION_MAP.keys():
+    if BRL in transaction['detail'] and transaction['title'] in PIX_TRANSACTION_MAP.keys():
         transaction['__typename'] = PIX_TRANSACTION_MAP[transaction['title']]
         transaction['amount'] = parse_float(transaction['detail'])
 
@@ -32,9 +33,9 @@ def parse_pix_transaction(transaction: dict) -> dict:
 
 def parse_generic_transaction(transaction: dict) -> dict:
     amount = None
-    if transaction['node']['detail'] and 'R$' in transaction['node']['detail']:
+    if transaction['node']['detail'] and BRL in transaction['node']['detail']:
         amount = parse_float(transaction['node']['detail'])
-    elif transaction['node']['footer'] and 'R$' in transaction['node']['footer']:
+    elif transaction['node']['footer'] and BRL in transaction['node']['footer']:
         amount = parse_float(transaction['node']['footer'])
 
     if amount:


Test patch:
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 3476a84..bf29261 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -71,6 +71,17 @@ def test_should_parse_failed_pix_transaction():
     assert parsed['amount'] == 3668.40
 
 
+def test_should_ignore_transactions_without_value():
+    transaction = base_generic_transaction.copy()
+    transaction['title'] = 'Transferência enviada'
+    transaction['detail'] = 'Something without money'
+
+    parsed = parse_pix_transaction(transaction)
+
+    assert parsed['__typename'] == 'GenericFeedEvent'
+    assert parsed.get('amount') is None
+
+
 def test_parse_generic_transaction_should_retrieve_amount_from_detail_when_contains_rs():
     transaction = create_edge_transaction()
     transaction['node']['detail'] = 'R$ 123,56'