mirror of
https://github.com/deesiigneer/pyspapi.git
synced 2026-04-20 04:25:25 +00:00
refactor: replace get_event_loop with asyncio.run for better async handling in example scripts
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user