Synchronous usage¶
glQiwiApi also coverage synchronous usage, you can use it like in the example.
Tip
Usage. You can use this sync adapter for any async function.
1import datetime
2
3from glQiwiApi import QiwiWrapper, sync
4
5TOKEN = 'Api token from https://qiwi.com/api'
6WALLET = '+phone_number'
7
8# As always, we create an instance of the class,
9# but pass on "without_context" as True
10wallet = QiwiWrapper(
11 api_access_token=TOKEN,
12 phone_number=WALLET,
13 without_context=True # add this param to use sync connector soon
14)
15
16
17def sync_function() -> None:
18 start_date = datetime.datetime.now() - datetime.timedelta(days=5)
19 # Use the sync () function and pass the function we want to execute
20 # without calling it, that is, pass it as a regular variable
21 result = sync(wallet.transactions, rows_num=50, start_date=start_date,
22 end_date=datetime.datetime.now())
23 print(result)
24
25
26sync_function()
Example of usage sync adapter for custom async function:
import asyncio
from glQiwiApi import sync
async def some_async():
await asyncio.sleep(2)
def main():
sync(some_async)
main()