-
-
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
1 parent
7446e8c
commit 4c76562
Showing
11 changed files
with
171 additions
and
39 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
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,27 +1,33 @@ | ||
import os | ||
import requests | ||
import sentry_sdk | ||
from sentry_sdk import capture_exception | ||
|
||
|
||
class OpenExchangeRatesError(Exception): | ||
"""Custom exception for Open Exchange Rates errors.""" | ||
|
||
print("OpenExchangeRatesError") | ||
# Initialize Sentry SDK (ensure this is done at the application startup) | ||
sentry_sdk.init( | ||
dsn=os.getenv("SENTRY_DSN"), # Replace with your Sentry DSN | ||
traces_sample_rate=1.0, # Adjust this based on your needs | ||
) | ||
|
||
|
||
def get_latest_exchange_rates(base_currency="USD"): | ||
api_key = os.getenv("OPENEXCHANGERATES_APP_ID") | ||
if not api_key: | ||
raise OpenExchangeRatesError( | ||
"OPENEXCHANGERATES_APP_ID is not set in the environment" | ||
) | ||
error_message = "OPENEXCHANGERATES_APP_ID is not set in the environment" | ||
capture_exception(Exception(error_message)) | ||
return {"error": error_message} | ||
|
||
url = f"https://openexchangerates.org/api/latest.json?app_id={api_key}&base={base_currency}" | ||
print(url) | ||
response = requests.get(url) | ||
print(response) | ||
if response.status_code != 200: | ||
raise OpenExchangeRatesError( | ||
f"Error fetching exchange rates: {response.json().get('error', 'Unknown error')}" | ||
) | ||
try: | ||
response = requests.get(url) | ||
print(response) | ||
if response.status_code != 200: | ||
error_message = f"Error fetching exchange rates: {response.json().get('error', 'Unknown error')}" | ||
capture_exception(Exception(error_message)) | ||
return {"error": error_message} | ||
|
||
return response.json() | ||
return response.json() | ||
except Exception as e: | ||
capture_exception(e) | ||
return {"error": str(e)} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.