-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.py
35 lines (27 loc) · 931 Bytes
/
async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from decimal import Decimal
import asyncio
import aiohttp
from time_it import time_it
import random
async def fetch_api(currency_to: str) -> dict:
url = f"https://economia.awesomeapi.com.br/{currency_to}/1"
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
response.raise_for_status()
return await response.json()
async def main() -> None:
"""
Makes a conversion between ARG currency and
USD currency.
"""
for _ in range(100):
currency_to = "USD-ARS"
amount = random.randint(10, 99999)
response = await fetch_api(currency_to)
change = Decimal(response[0].get("high"))
print(f"With {amount} dollars you will get {change*amount} Argentine pesos")
@time_it
def call_async_main():
asyncio.run(main())
if __name__ == "__main__":
call_async_main()