code/drinks_lib.py
def import_recipe():
	""" opens a file prompt to import a new recipe
	returns True if successfull, False if an error occurred
	"""
	file_path = prompt_file()			# select a file
	print("[DR IR] 1/6 file path:", file_path)

	file = open(file_path, 'r')							# read the file and do a compatability check
	lines = file.readlines()
	file.close()
	for idx, i in enumerate(lines):						# remove trailing newline characters
		if lines[idx].endswith('\n'):
			lines[idx] = lines[idx][:-1]

	print("[DR IR] 2/6 could read file and removed newline characters")

	new_drinks = []
	
	try:											# trying to convert the second param of the instructions to int
		for i in lines[1:]:
			splitted = i.split(',')
			if not splitted[0] in drinks:
				new_drinks.append(splitted[0])
			amount = int(splitted[1])
	except ValueError:
		print("[DR IR] 3/6 ValueError: couldn't convert to int")
		return(False)
	except IndexError:
		print("[DR IR] 3/6 IndexError: couldn't split Commands into drink and amount needed")
		return(False)

	print("[DR IR] 3/6 No faulty units")

	# if necessary, add new drinks to the list
	print("[DR IR] 4/6 These new drinks will be added:", new_drinks)
	success = add_drinks(new_drinks)
	if success:
		print("[DR IR] 4/6 New drinks added successfully")
	else:
		print("[DR IR] 4/6 Error occurred")


	print("[DR IR] 5/6 copy drink to recipe folder")
	try:
		split = file_path.split('/')
		filename = split[-1]
		copyfile(file_path, gl.gen_path + "/src/recipes/" + filename)
	except Exception:
		print("[DR IR] an error occurred while copying the file")
		return False

	# update recipe and drink lists
	update_recipes_and_drinks()
	print("[DR SI] 6/6 update recipes and drinks")

	print("[DR SI] all done")
	return True
 opens a file prompt to import a new recipe
	returns True if successfull, False if an error occurred
	
opens a file prompt to import a new recipe
returns True if successfull, False if an error occurred
opens a file prompt to import a new recipe returns True if successfull False if an error occurred
def import_recipe():
	file_path = prompt_file()			
	print("[DR IR] 1/6 file path:", file_path)
	file = open(file_path, 'r')							
	lines = file.readlines()
	file.close()
	for idx, i in enumerate(lines):						
		if lines[idx].endswith('\n'):
			lines[idx] = lines[idx][:-1]
	print("[DR IR] 2/6 could read file and removed newline characters")
	new_drinks = []
	try:											
		for i in lines[1:]:
			splitted = i.split(',')
			if not splitted[0] in drinks:
				new_drinks.append(splitted[0])
			amount = int(splitted[1])
	except ValueError:
		print("[DR IR] 3/6 ValueError: couldn't convert to int")
		return(False)
	except IndexError:
		print("[DR IR] 3/6 IndexError: couldn't split Commands into drink and amount needed")
		return(False)
	print("[DR IR] 3/6 No faulty units")
	print("[DR IR] 4/6 These new drinks will be added:", new_drinks)
	success = add_drinks(new_drinks)
	if success:
		print("[DR IR] 4/6 New drinks added successfully")
	else:
		print("[DR IR] 4/6 Error occurred")
	print("[DR IR] 5/6 copy drink to recipe folder")
	try:
		split = file_path.split('/')
		filename = split[-1]
		copyfile(file_path, gl.gen_path + "/src/recipes/" + filename)
	except Exception:
		print("[DR IR] an error occurred while copying the file")
		return False
	update_recipes_and_drinks()
	print("[DR SI] 6/6 update recipes and drinks")
	print("[DR SI] all done")
	return True
def import_recipe ( ) : file_path = prompt_file ( ) print ( "[DR IR] 1/6 file path:" , file_path ) file = open ( file_path , 'r' ) lines = file . readlines ( ) file . close ( ) for idx , i in enumerate ( lines ) : if lines [ idx ] . endswith ( '\n' ) : lines [ idx ] = lines [ idx ] [ : - 1 ] print ( "[DR IR] 2/6 could read file and removed newline characters" ) new_drinks = [ ] try : for i in lines [ 1 : ] : splitted = i . split ( ',' ) if not splitted [ 0 ] in drinks : new_drinks . append ( splitted [ 0 ] ) amount = int ( splitted [ 1 ] ) except ValueError : print ( "[DR IR] 3/6 ValueError: couldn't convert to int" ) return ( False ) except IndexError : print ( "[DR IR] 3/6 IndexError: couldn't split Commands into drink and amount needed" ) return ( False ) print ( "[DR IR] 3/6 No faulty units" ) print ( "[DR IR] 4/6 These new drinks will be added:" , new_drinks ) success = add_drinks ( new_drinks ) if success : print ( "[DR IR] 4/6 New drinks added successfully" ) else : print ( "[DR IR] 4/6 Error occurred" ) print ( "[DR IR] 5/6 copy drink to recipe folder" ) try : split = file_path . split ( '/' ) filename = split [ - 1 ] copyfile ( file_path , gl . gen_path + "/src/recipes/" + filename ) except Exception : print ( "[DR IR] an error occurred while copying the file" ) return False update_recipes_and_drinks ( ) print ( "[DR SI] 6/6 update recipes and drinks" ) print ( "[DR SI] all done" ) return True
opens a file prompt to import a new recipe
returns True if successfull, False if an error occurred
opens a file prompt to import a new recipe returns True if successfull False if an error occurred
""" opens a file prompt to import a new recipe
	returns True if successfull, False if an error occurred
	""" # select a file # read the file and do a compatability check # remove trailing newline characters # trying to convert the second param of the instructions to int # if necessary, add new drinks to the list # update recipe and drink lists