-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |