-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the api of the currency to be imhotep api
- Loading branch information
Showing
1 changed file
with
9 additions
and
20 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 |
---|---|---|
|
@@ -129,27 +129,16 @@ def send_verification_mail_code(user_mail): | |
|
||
def set_currency_session(favorite_currency): | ||
primary_api_key = os.getenv('EXCHANGE_API_KEY_PRIMARY') | ||
secondary_api_key = os.getenv('EXCHANGE_API_KEY_SECONDARY') | ||
third_api_key = os.getenv('EXCHANGE_API_KEY_THIRD') | ||
|
||
data = None | ||
try: | ||
response = requests.get(f"https://v6.exchangerate-api.com/v6/{primary_api_key}/latest/{favorite_currency}") | ||
response = requests.get(f"https://imhotepexchangeratesapi.pythonanywhere.com/latest_rates/{primary_api_key}/{favorite_currency}") | ||
data = response.json() | ||
rate = data["conversion_rates"] | ||
except: | ||
try: | ||
response = requests.get(f"https://v6.exchangerate-api.com/v6/{secondary_api_key}/latest/{favorite_currency}") | ||
data = response.json() | ||
rate = data["conversion_rates"] | ||
except: | ||
try: | ||
response = requests.get(f"https://v6.exchangerate-api.com/v6/{third_api_key}/latest/{favorite_currency}") | ||
data = response.json() | ||
rate = data["conversion_rates"] | ||
except requests.RequestException as e: | ||
print(f"Failed to fetch exchange rates: {e}") | ||
return None | ||
rate = data["data"] | ||
|
||
except requests.RequestException as e: | ||
print(f"Failed to fetch exchange rates: {e}") | ||
return None | ||
|
||
if rate: | ||
session["rate"] = rate | ||
|
@@ -420,14 +409,14 @@ def request_amount_exceed(error): | |
@app.errorhandler(405) | ||
def page_not_found(error): | ||
return render_template('error_handle.html', error_code = "405", error_description = "Method Not Allowed."), 405 | ||
|
||
''' | ||
@app.errorhandler(Exception) | ||
def server_error(error): | ||
return render_template('error_handle.html', error_code = "500", error_description = "Something went wrong."), 500 | ||
@app.errorhandler(500) | ||
def internal_server_error(error): | ||
return render_template('error_handle.html', error_code = "500", error_description="Something Went Wrong."), 500 | ||
return render_template('error_handle.html', error_code = "500", error_description="Something Went Wrong."), 500''' | ||
|
||
@app.route("/", methods=["GET"]) | ||
def index(): | ||
|
@@ -511,7 +500,7 @@ def mail_verification(): | |
) | ||
db.session.commit() | ||
try: | ||
msg = Message('Email Changed', sender='[email protected]', recipients=[user_mail]) | ||
msg = Message('Email Verified', sender='[email protected]', recipients=[user_mail]) | ||
msg.body = f"Welcome {user_username} To Imhotep Finacial Manager" | ||
mail.send(msg) | ||
except: | ||
|