python pyqiwi при попытке записать транзакции и отследить новую возникает клонирование транзакции
Суть проблемы: при пополнении кошелька, пишет фразу "пополнение на" больше 1 раза, очень прошу подсказать в чем моя ошибка, вот сам код:
import pyqiwi
import time
import os
wallet = pyqiwi.Wallet(token='ТОКЕН', number='ТЕЛЕФОН')
tranzactions = []
print(wallet.history(rows=50, operation='IN').get("transactions")[2])
for i in wallet.history(rows=50, operation='IN').get("transactions"):
tranzactions.append(str(i.raw['txnId']))
while True:
time.sleep(1)
tranzs = wallet.history(rows=50, operation='IN').get("transactions")
for i in tranzs:
if str(i.raw['txnId']) not in tranzactions:
tranzactions = tranzactions[1:] + tranzactions[:1]
tranzactions[-1] = str(i.raw['txnId'])
if i.comment != None and str(i.comment) in os.listdir('ids'):
print(f'Пополнение на {str(i.sum.amount)}')
balance = open('ids/' + str(i.comment), 'r+').readlines()[0]
open('ids/' + str(i.comment), 'r+').write(str(int(balance) + i.sum.amount))
print(tranzactions[47:])
print('Один цикл')