def update_currency(self): # text input enable if self.root.ids.input_country_amount.disabled is True and self.root.ids.input_home_country_amount.disabled is True: self.root.ids.input_country_amount.disabled = False self.root.ids.input_home_country_amount.disabled = False self.root.ids.input_country_amount.text = '' self.root.ids.input_home_country_amount.text = '' return self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False # currency exchange self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text # spinner / home country name grabbing self.country1 = self.root.ids.home_country_label.text self.country2 = self.root.ids.country_selection.text # checks if spinner selection is blank if self.country2 is "": self.country2 = self.root.ids.country_selection.text = self.current_location # gets country details self.country_details1 = currency.get_details(self.country1) self.country_details2 = currency.get_details(self.country2) # checks to see if there was an inputted currency in the "home country" textbox, if there is no value, then it is assumed that the spinner country textbox has an inputted value. if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) print(self.amount2) self.amount2 = round(self.amount2, 3) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # checks to see if there was an inputted currency in the spinner country textbox, if there is no value, then it is assumed that the "home country" textbox has an inputted value. elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time)
def validate_config(self): locations = self.locations details = self.details text_file = open("config.txt", "r") # getting the trip details lines = text_file.readlines() print(lines[0]) country = lines[0].replace('\n', '') tuple = currency.get_details(country) if len(tuple) == 0: self.root.ids.trip_detail_info.text = "Invalid country name \n " + country return try: for each_line in lines[1:len(lines)]: each_line_tuple_split = each_line.split(",") each_line_tuple_split_country = each_line_tuple_split[ 0].replace("\n", "") result_tuple = currency.get_details( each_line_tuple_split_country) if len(result_tuple) != 0: print "" self.state_codes.append(each_line_tuple_split_country) self.valid_state = False details.add(each_line_tuple_split_country, each_line_tuple_split[1].replace("\n", ""), each_line_tuple_split[2].replace("\n", "")) else: self.root.ids.trip_detail_info.text = "Invalid country name \n " + each_line_tuple_split_country self.valid_state = False return print(each_line_tuple_split_country) except trip.Error as details_error: print("Error :" + details_error.msg) self.root.ids.trip_detail_info.text = "Invalid trip details \n " + details_error.msg self.valid_state = False return self.root.ids.home_country.text = tuple[0] self.root.ids.trip_detail_info.text = "trip details accepted" self.current_date = datetime.datetime.now().strftime("%Y/%m/%d") self.root.ids.current_date.text = "Today's Date is \n" + self.current_date self.current_date_country = details.current_country(self.current_date) self.root.ids.current_trip_location.text = "Current Trip Location \n" + self.current_date_country self.valid_state = True
def validate_config(self): locations = self.locations details = self.details text_file = open("config.txt", "r") # getting the trip details lines = text_file.readlines() print(lines[0]) country = lines[0].replace('\n','') tuple = currency.get_details(country) if len(tuple) == 0: self.root.ids.trip_detail_info.text = "Invalid country name \n " + country return try: for each_line in lines[1:len(lines)]: each_line_tuple_split = each_line.split(",") each_line_tuple_split_country = each_line_tuple_split[0].replace("\n","") result_tuple = currency.get_details(each_line_tuple_split_country) if len(result_tuple) != 0: print "" self.state_codes.append(each_line_tuple_split_country) self.valid_state = False details.add(each_line_tuple_split_country, each_line_tuple_split[1].replace("\n", ""), each_line_tuple_split[2].replace("\n","")) else: self.root.ids.trip_detail_info.text = "Invalid country name \n " + each_line_tuple_split_country self.valid_state = False return print(each_line_tuple_split_country) except trip.Error as details_error: print("Error :"+ details_error.msg) self.root.ids.trip_detail_info.text = "Invalid trip details \n " + details_error.msg self.valid_state = False return self.root.ids.home_country.text = tuple[0] self.root.ids.trip_detail_info.text = "trip details accepted" self.current_date = datetime.datetime.now().strftime ("%Y/%m/%d") self.root.ids.current_date.text = "Today's Date is \n"+self.current_date self.current_date_country = details.current_country(self.current_date) self.root.ids.current_trip_location.text = "Current Trip Location \n" + self.current_date_country self.valid_state = True
def update_currency(self): # text input enable if self.root.ids.input_country_amount.disabled is True and self.root.ids.input_home_country_amount.disabled is True: self.root.ids.input_country_amount.disabled = False self.root.ids.input_home_country_amount.disabled = False self.root.ids.input_country_amount.text = '' self.root.ids.input_home_country_amount.text = '' return self.root.ids.input_country_amount.focus = False self.root.ids.input_home_country_amount.focus = False # currency exchange self.currency1 = self.root.ids.input_home_country_amount.text self.currency2 = self.root.ids.input_country_amount.text # spinner / home country name grabbing self.country1 = self.root.ids.home_country_label.text self.country2 = self.root.ids.country_selection.text # checks if spinner selection is blank if self.country2 is "": self.country2 = self.root.ids.country_selection.text = self.current_location # gets country details self.country_details1 = currency.get_details(self.country1) self.country_details2 = currency.get_details(self.country2) # checks to see if there was an inputted currency in the "home country" textbox, if there is no value, then it is assumed that the spinner country textbox has an inputted value. if self.currency1 is "": self.amount2 = currency.convert(self.currency2, self.country_details2[1], self.country_details1[1]) print(self.amount2) self.amount2 = round(self.amount2, 3) if self.amount2 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_home_country_amount.text = str(self.amount2) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time) # checks to see if there was an inputted currency in the spinner country textbox, if there is no value, then it is assumed that the "home country" textbox has an inputted value. elif self.currency2 is "": self.amount1 = currency.convert(self.currency1, self.country_details1[1], self.country_details2[1]) self.amount1 = round(self.amount1, 3) print(self.amount1) if self.amount1 is -1: self.root.ids.input_country_amount.disabled = True self.root.ids.input_home_country_amount.disabled = True self.root.ids.input_country_amount.text = str(self.amount1) current_time = time.strftime("%H:%M:%S") self.root.ids.status.text = "updated at {}".format(current_time)
def change_state(self, state_code): if self.is_currency_updated_flag == False: print("Flag not updated") return new_country_tuple = currency.get_details(state_code) print(new_country_tuple) print(self.from_country_tuple) if (self.from_country_tuple and new_country_tuple[1] == self.from_country_tuple[1]): self.conversion_factor = 1 self.reverse_conversion_factor = 1 return if (new_country_tuple[1] == self.home_country_tuple[1]): self.home_country_tuple = new_country_tuple self.from_country_tuple = new_country_tuple self.conversion_factor = 1 self.reverse_conversion_factor = 1 else: self.from_country_tuple = new_country_tuple self.get_currency_conversion() current_time = datetime.datetime.now().strftime("%H:%M:%S") self.root.ids.trip_detail_info.text = "Updated at \n" + current_time print(self.from_country_tuple)
def change_state(self, state_code): if self.is_currency_updated_flag == False: print("Flag not updated") return new_country_tuple = currency.get_details(state_code) print(new_country_tuple) print(self.from_country_tuple) if (self.from_country_tuple and new_country_tuple[1] == self.from_country_tuple[1]): self.conversion_factor = 1 self.reverse_conversion_factor = 1 return if (new_country_tuple[1] == self.home_country_tuple[1]): self.home_country_tuple = new_country_tuple self.from_country_tuple = new_country_tuple self.conversion_factor = 1 self.reverse_conversion_factor = 1 else: self.from_country_tuple = new_country_tuple self.get_currency_conversion() current_time = datetime.datetime.now().strftime ("%H:%M:%S") self.root.ids.trip_detail_info.text = "Updated at \n" + current_time print(self.from_country_tuple)
def set_selected_country( self ): #called after on_text at spinner to set the selected country self.selected_country_details = currency.get_details( self.root.ids.spinner_selection.text ) #getting full details of the selected country self.convert() #calls convert()
def load_data(self): # load date and store in label, set last updated time self.root.ids.lbl_date.text = "Today is: " + time.strftime("%Y/%m/%d") self.root.ids.lbl_status.text = "Last updated: " + time.strftime("%H:%M:%S") + "\n" + time.strftime("%Y/%m/%d") # start conversion, store rate, Enable Textinput, if something goes wrong they will be disabled self.root.ids.txt_foreign_amount.disabled = False self.root.ids.txt_home_amount.disabled = False self.home_currency = get_details(self.root.ids.lbl_home_country.text) self.target_currency = get_details(self.root.ids.country_spinner.text) if self.root.ids.country_spinner.text != "": try: self.rate = convert(1, self.home_currency[1], self.target_currency[1]) except: self.root.ids.lbl_error.text = "Error: Null Rate" self.root.ids.txt_foreign_amount.disabled = True self.root.ids.txt_home_amount.disabled = True else: self.root.ids.country_spinner.text = self.current_country
def button_pressed(self, button): self.is_currency_updated_flag = True if self.valid_state: print('app: ' + str(self)) # this is the app object print(self.details.current_country(self.current_date)) self.root.ids.home_country_currency_amount.disabled = False self.root.ids.from_country_currency_amount.disabled = False self.root.ids.update_currency.disabled = True self.root.ids.from_country_currency_amount.focus = True self.home_country_tuple = currency.get_details(self.root.ids.home_country.text) #self.from_country_tuple = currency.get_details(self.current_date_country) self.root.ids.state_selection.text = self.details.current_country(self.current_date)
def __init__(self, **kwargs): super(CurrencyConverter, self).__init__(**kwargs) # Retrieve today's date using time builtin in format YYYY/MM/DD self.todays_date = time.strftime("%Y/%m/%d") # Retrieve current time using time builtin self.time = time.strftime('%H:%M:%S') self.forward_conversion_rate = -1 self.backward_conversion_rate = -1 self.details = Details() self.country_list = [] self.home_country = "" self.load_config() self.update_button_disabled = "" try: self.current_country = self.details.current_country(self.todays_date) self.home_currency = get_details(self.home_country)[1] # to retrieve code self.target_currency = get_details(self.current_country)[1] except Error: self.current_country = "Could not be found" self.target_country = self.current_country self.update_button_disabled = "True"
def button_pressed(self, button): self.is_currency_updated_flag = True if self.valid_state: print('app: ' + str(self)) # this is the app object print(self.details.current_country(self.current_date)) self.root.ids.home_country_currency_amount.disabled = False self.root.ids.from_country_currency_amount.disabled = False self.root.ids.update_currency.disabled = True self.root.ids.from_country_currency_amount.focus = True self.home_country_tuple = currency.get_details( self.root.ids.home_country.text) #self.from_country_tuple = currency.get_details(self.current_date_country) self.root.ids.state_selection.text = self.details.current_country( self.current_date)
def get_home_country(self): #getting home country try: with open('config.txt', encoding='utf8') as list_countries: #opens the txt file for line in list_countries: #gets each line in the txt file if ',' not in line: #checks for ',' in the line self.home_country = line.strip( ) #getting the home country name (strip() for removing '\n' self.home_country_details = currency.get_details( self.home_country) #getting full details of the home country self.status_bar_text = str( "TRIP DETAILS ACCEPTED") #status bar update except: self.status_bar_text = str( "TRIP DETAILS INVALID") #status bar update
class Error(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) if __name__ == '__main__': from currency import get_details import time print('test country class') country = Country('Australia', 'AUD', '$') print(country.formatted_amount(10.95)) country = Country.make(get_details("Turkey")) print(country.formatted_amount(10.95)) print('test tripdetails class') trip = Details() trip.add(country, "2015/09/05", "2015/09/20") trip.add(country, "2015/09/21", "2016/09/20") try: print(trip.current_country("2015/09/01")) except Error as error: print(error.value) print(trip.current_country(time.strftime('%Y/%m/%d'))) try: trip.add(country, "2015/09/05", "2015/09/20")
__author__ = 'connor' import web_utility import currency amount = input("Amount: ") currentC = input("Current: ") travelC = input("Travel: ") currentCountry = currency.get_details(currentC) travelCountry = currency.get_details(travelC) result = currency.convert(amount, currentCountry[1], travelCountry[1]) print(result)
def get_current_country_details( self): #getting full details of the current country self.current_country_details = currency.get_details( self.current_country.strip() ) #getting full details (according to the current date)
__author__ = 'connor' import trip import currency currentCountry = currency.get_details(input("Country")) country = trip.Country(currentCountry[0],currentCountry[1],currentCountry[2]) output = country.Currency(1000) print(output) print(country)
class Error(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) if __name__ == '__main__': from currency import get_details import time print('test country class') country = Country('Australia', 'AUD', '$') print(country.formatted_amount(10.95)) country = Country.make(get_details("Turkey")) print(country.formatted_amount(10.95)) print('test tripdetails class') trip = Details() trip.add(country, "2015/09/05", "2015/09/20") trip.add(country, "2015/09/21", "2016/09/20") try: print(trip.current_country("2015/09/01")) except Error as error: print(error.value) print(trip.current_country(time.strftime('%Y/%m/%d'))) try: trip.add(country, "2015/09/05", "2015/09/20")
__author__ = 'connor' import trip import currency add = True trips = trip.Details() while add == True: if trips.isEmpty() == True: first = "first" else: first = "next" country = input("Type country to travel too " + first + "" ": ") start_date = input("Type the date you wish to go to the country. eg, 30 12 15: ") end_date = input("Type the date you wish to return. eg, 31 12 15: ") trips.add(country, start_date, end_date) if input("Would you like to add another trip? Y or N: ") == "Y": add = True else: add = False currentCountry = currency.get_details(input("Type current country: ")) tripCountry = currency.get_details(trips.current_country(input("Add Current Date. eg, 31 12 15: "))) currentCountryInfo = trip.Country(currentCountry[0], currentCountry[1], currentCountry[2]) tripCountryInfo = trip.Country(tripCountry[0], tripCountry[1], tripCountry[2]) result = currency.convert(input("Type the amount you wish to convert: "), currentCountry[1], tripCountry[1]) output = tripCountryInfo.Currency(result) print(output)
elif x + 1 == len(self.location): raise Error("THERE IS NO COUNTRY WITH THAT DATE") except Error as e: print(e) def is_empty(self): if not self.location: print("THIS LOCATION LIST IS EMPTY") if __name__ == "__main__": #executed or imported #code testing import currency #importing from currency testing_country = Country(*currency.get_details("Singapore")) print(testing_country) print(testing_country.format_currency(10.10), "\n\n") testing_date = Details() testing_date.is_empty() print(testing_date.location, "\n\n") Details.add(testing_date, "India", "10/12/2010", "25/12/2010") print(testing_date.location) Details.add(testing_date, "Saudi Arabia", "11/10/2011", "22/12/2011") print(testing_date.location, "\n\n") print(Details.current_country(testing_date, "20/12/2010")) print(Details.current_country(testing_date, "12/10/2003")) testing_date.is_empty()