def check_payment(user_id):
conn = sqlite3.connect('data.db')
cur = conn.cursor()
cur.execute('''SELECT qiwi_number FROM config''')
numb = cur.fetchall()
QIWI_NUMBER = list(numb[0])[0]
cur.execute('''SELECT qiwi_token FROM config''')
to = cur.fetchall()
QIWI_TOKEN = list(to[0])[0]
try:
session = requests.Session()
session.headers['authorization'] = 'Bearer ' + QIWI_TOKEN
parameters = {'rows': '5'}
h = session.get(
'https://edge.qiwi.com/payment-history/v1/persons/{}/payments'.format(QIWI_NUMBER),
params=parameters)
req = json.loads(h.text)
result = cur.execute(f'SELECT * FROM payment_query WHERE user_id = {user_id}').fetchone()
comment = str(result[2])
sum = result[1]
for i in range(len(req['data'])):
if comment in str(req['data'][i]['comment']):
print(round(float(req["data"][i]["sum"]["amount"])))
print(sum)
if round(float(req["data"][i]["sum"]["amount"])) == sum:
cur.execute(f'UPDATE users SET access = "True" WHERE id = "{user_id}"')
conn.commit()
cur.execute(f'DELETE FROM payment_query WHERE user_id = "{user_id}"')
conn.commit()
return 1
except Exception as e:
print(e)
return 0
При выполнении float и sum - одинаковые значения, но они не равны, почему?
EPS = 1e-6
abs(a - b) < EPS