From 6906afb090dd26c1718985d23c593dfd3440aa81 Mon Sep 17 00:00:00 2001 From: deesiigneer Date: Fri, 30 Jan 2026 22:36:18 +0000 Subject: [PATCH] refactor: replace get_event_loop with asyncio.run for better async handling in example scripts --- examples/get_user.py | 8 ++++---- examples/me.py | 8 ++++---- examples/payments.py | 28 ++++++++++++++++------------ examples/transaction.py | 16 ++++++++-------- examples/webhook.py | 10 +++++----- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/examples/get_user.py b/examples/get_user.py index b2e5a22..d5865da 100644 --- a/examples/get_user.py +++ b/examples/get_user.py @@ -1,7 +1,8 @@ +import asyncio from pyspapi import SPAPI -from asyncio import get_event_loop -spapi = SPAPI(card_id='CARD_ID', token='TOKEN') +spapi = SPAPI(card_id="CARD_ID", token="TOKEN") + async def main(): @@ -11,5 +12,4 @@ async def main(): print(card.name, card.number) -loop = get_event_loop() -loop.run_until_complete(main()) +asyncio.run(main()) diff --git a/examples/me.py b/examples/me.py index 2edde9a..02ec08a 100644 --- a/examples/me.py +++ b/examples/me.py @@ -1,12 +1,12 @@ +import asyncio from pyspapi import SPAPI -from asyncio import get_event_loop -spapi = SPAPI(card_id='CARD_ID', token='TOKEN') +spapi = SPAPI(card_id="CARD_ID", token="TOKEN") async def main(): me = await spapi.me print(me) -loop = get_event_loop() -loop.run_until_complete(main()) + +asyncio.run(main()) diff --git a/examples/payments.py b/examples/payments.py index 430db46..444dd69 100644 --- a/examples/payments.py +++ b/examples/payments.py @@ -1,21 +1,25 @@ +import asyncio from pyspapi import SPAPI from pyspapi.types import Item -from asyncio import get_event_loop -spapi = SPAPI(card_id='CARD_ID', token='TOKEN') +spapi = SPAPI(card_id="CARD_ID", token="TOKEN") -items = [Item('first item', 1, 2, 'first item comment').to_json(), - Item('second item', 3, 4, 'second item comment').to_json()] + +items = [ + Item("first item", 1, 2, "first item comment").to_json(), + Item("second item", 3, 4, "second item comment").to_json(), +] async def main(): - print(await spapi.create_payment(items=items, - redirect_url='https://www.google.com/', - webhook_url='https://www.google.com/', - data='some-data' - ) - ) + print( + await spapi.create_payment( + items=items, + redirect_url="https://www.google.com/", + webhook_url="https://www.google.com/", + data="some-data", + ) + ) -loop = get_event_loop() -loop.run_until_complete(main()) +asyncio.run(main()) diff --git a/examples/transaction.py b/examples/transaction.py index 4d0ead0..73c4fcf 100644 --- a/examples/transaction.py +++ b/examples/transaction.py @@ -1,15 +1,15 @@ -from asyncio import get_event_loop - +import asyncio from pyspapi import SPAPI -spapi = SPAPI(card_id='CARD_ID', token='TOKEN') +spapi = SPAPI(card_id="CARD_ID", token="TOKEN") + async def main(): - new_balance = await spapi.create_transaction(receiver='77552', - amount=1, - comment='test') + new_balance = await spapi.create_transaction( + receiver="20199", amount=1, comment="test" + ) print(new_balance) -loop = get_event_loop() -loop.run_until_complete(main()) + +asyncio.run(main()) diff --git a/examples/webhook.py b/examples/webhook.py index 48cc011..6d86517 100644 --- a/examples/webhook.py +++ b/examples/webhook.py @@ -1,13 +1,13 @@ +import asyncio from pyspapi import SPAPI -from asyncio import get_event_loop -spapi = SPAPI(card_id='CARD_ID', token='TOKEN') +spapi = SPAPI(card_id="CARD_ID", token="TOKEN") # print(spapi.webhook_verify(data='webhook_data', header='webhook_header')) async def main(): - print(await spapi.update_webhook(url='https://example.com/webhook')) + print(await spapi.update_webhook(url="https://example.com/webhook")) -loop = get_event_loop() -loop.run_until_complete(main()) + +asyncio.run(main())