Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from forex_python.converter import CurrencyRates
- from datetime import datetime
- def parse_curr_val(value):
- c = CurrencyRates()
- curr_list = c.get_rates('USD').keys()
- if value in curr_list:
- return True
- else:
- return False
- def isfloat(value):
- try:
- float(value)
- return True
- except ValueError:
- return False
- def date_valid(date):
- try:
- datetime.strptime(date, '%Y-%m-%d')
- return True
- except ValueError:
- return False
- c = CurrencyRates()
- print("\tHELLO, dear user! My name is LISA and I want to present you my APPLICATION")
- with open('get_history.txt', 'w') as f:
- pass
- while True:
- print("\n Enter 1 to convert currency\n Enter 2 to get conversion history\n Enter 3 to exit the program")
- command = input()
- if command == '1':
- print('\nEnter the currency')
- first_curr = input().upper()
- while not parse_curr_val(first_curr):
- print('\nWrong format, enter the currency')
- first_curr = input().upper()
- print('\nEnter the currency you want to convert to')
- second_curr = input().upper()
- while not parse_curr_val(second_curr):
- print('\nWrong format, enter the currency you want to convert to')
- second_curr = input().upper()
- print('\nHow much? Enter amount of currency')
- amount = input()
- while not isfloat(amount):
- print('\nError, please, enter digit value')
- amount = input()
- amount = float(amount)
- print('\nWould you like to enter the date? Enter yes or no')
- dd = input().lower()
- while dd not in ['yes', 'no']:
- print("\nERROR. Enter 'yes' or 'no'")
- dd = input().lower()
- if dd == 'yes':
- print('\nEnter the date in format YYYY-MM-DD')
- curr_date = input()
- while not date_valid(curr_date):
- print("\nERROR. Enter the date in format YYYY-MM-DD")
- curr_date = input()
- curr_date = datetime.strptime(curr_date, '%Y-%m-%d').date()
- itog = round(c.convert(first_curr, second_curr, amount, curr_date), 2)
- with open('get_history.txt', 'a') as f:
- f.write(first_curr + ' ' + second_curr + ' ' + str(amount) + ' ' \
- + str(curr_date) + ' ' + str(itog) + '\n')
- print('\n Result of conversion --', itog)
- elif dd == 'no':
- itog = round(c.convert(first_curr, second_curr, amount), 2)
- with open('get_history.txt', 'a') as f:
- f.write(first_curr + ' ' + second_curr + ' ' + str(amount) + ' ' + str(itog) + '\n')
- print('\n Result of conversion --', itog)
- elif command == '2':
- print('--- Conversion history ---\n')
- with open('get_history.txt', 'r') as f:
- print(f.read())
- elif command == '3':
- print('\nGoodbye!')
- break
- else:
- print("\nERROR")
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement