Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
fabaff committed Oct 15, 2021
1 parent d70dd5f commit b53e41e
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
"""Sample code for the wrapper to interact with the currencylayer API."""
"""Sample code for interacting with the currencylayer API."""
import asyncio

import aiohttp

from aiocurrencylayer import CurrencyLayer

API_KEY = 'YOUR_CURRENCYLAYER_API_KEY'
QUOTE = 'CHF'
SOURCE = 'USD'
API_KEY = "YOUR_API_KEY"
QUOTE = "CHF"
SOURCE = "USD"


async def main():
"""The main part of the example script."""
async with aiohttp.ClientSession() as session:
currency = CurrencyLayer(loop, session, API_KEY, source=SOURCE)
currency = CurrencyLayer(API_KEY, source=SOURCE)

# Get the data
await currency.get_data()
# Get the data
await currency.get_data()

# Validate the API key
if await currency.validate_api_key() is False:
print(currency.data['error']['info'].split('.')[0])
return
# Validate the API key
if currency.validate_api_key is False:
print(currency.data["error"]["info"].split(".")[0])

# Check if it's a free plan
if await currency.check_free_plan() is True:
print(
"An API key for free plan is used, only USD as source allowed")
return
print("Supported currencies:", len(currency.supported_currencies))

print("Supported currencies:",
len(await currency.supported_currencies()))
# Get all quotes (identical to currency.quotes), use quote=CURRENCY
# to initialize the object to only get one currency
print(currency.quote)

# Get all quotes (identical to currency.quotes), use quote=CURRENCY
# to initialize the object to only get one currency
print(currency.quote)
# Get a single quote
print(QUOTE, currency.quotes[QUOTE])

# Get a single quote
print(QUOTE, currency.quotes[QUOTE])

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

0 comments on commit b53e41e

Please sign in to comment.