Beispiel #1
0
# Main Body of Script  ---------------------------------------------------- #
# TODO: Add Data Code to the Main body
# Load data from file into a list of employee objects when script starts
lstFile = FP.read_data_from_file('EmployeeData.txt')
lstTable = []
for line in lstFile:
    lstTable.append(EMP(line[0].strip(), line[1].strip(), line[2].strip()))
# Show user a menu of options
while (True):
    try:
        IO.print_menu_items()
        # Get user's menu option choice
        option = IO.input_menu_options()
        # Show user current data in the list of employee objects
        if option == '1':
            IO.print_current_list_items(lstTable)
    # Let user add data to the list of employee objects
        elif option == '2':
            lstTable.append(IO.input_employee_data())
    # let user save current data to file
        elif option == '3':
            FP.save_data_to_file('EmployeeData.txt', lstTable)
    # Let user exit program
        elif option == '4':
            print('Thanks, goodbye')
            break

        else:
            print('Please enter a valid choice.')

    except ValueError as e:
try:
    file_name = "EmployeeData.txt"
    list_of_employees = []
    input = None
    # Load data from file into a list of employee objects when script starts
    lstFileData = Fp.read_data_from_file(file_name)
    for line in lstFileData:
        list_of_employees.append(E(line[0], line[1], line[2].strip()))
    # Show user a menu of options
    while (True):
        Eio.print_menu_items()
        # Get user's menu option choice
        input = Eio.input_menu_options()
        # Show user current data in the list of employee objects
        if input == "1":
            Eio.print_current_list_items(list_of_employees)
        # Let user add data to the list of employee objects
        elif input == "2":
            new_data = Eio.input_employee_data()
            list_of_employees.append(new_data)
            print("New employee data successfully added!")
        # let user save current data to file
        elif input == "3":
            print(Fp.save_data_to_file(file_name, list_of_employees))
        # Let user exit program
        elif input == "4":
            break
except Exception as e:
    print(e, e.__doc__, type(e), sep="\n")
# Main Body of Script  ---------------------------------------------------- #
# Test Person class from DataClasses module
objP1 = P("Nacho", "Libre")
objP2 = P("Steven", "Esqueleto")
objP3 = P("Sister", "Encarnación")
lstTable = [objP1, objP2, objP3]
for row in lstTable:
    print(row.to_string(), type(row))  # Check person objects

# Test Employee class from DataClass module adding employee number (use existing data, not re-enter)
objE1 = Emp(1, objP1.first_name, objP1.last_name)
objE2 = Emp(2, objP2.first_name, objP2.last_name)
objE3 = Emp(3, objP3.first_name, objP3.last_name)
lstEmployees = [objE1, objE2, objE3]
for row in lstEmployees:
    print(row.to_string(), type(row))  # Check employee objects

#  Test FileProcessor class from ProcessingClasses module
FP.save_data_to_file("EmployeeData.txt", lstEmployees)  # Save data
lstFileData = FP.read_data_from_file("EmployeeData.txt")  # Read data back in
lstEmployees.clear()  # Clear list
for line in lstFileData:  # Repopulate list
    lstEmployees.append(Emp(line[0], line[1], line[2].strip()))
for row in lstEmployees:  # Print list
    print(row.to_string(), type(row))

# Test IO classes
Eio.print_menu_items()  # check menu print
Eio.print_current_list_items(lstEmployees)  #
print(Eio.input_employee_data())
print(Eio.input_menu_options())
Beispiel #4
0
from IOClasses import EmployeeIO

# Test data module - class Person
objP1 = Person("Bob", "Smith")
objP2 = Person("Sue", "Jones")
lstTable = [objP1, objP2]
for row in lstTable:
    print(row.to_string(), type(row))

# Test data module - class Employee
objP1 = Employee(1, "Bob", "Smith")
objP2 = Employee(2, "Sue", "Jones")
lstTable = [objP1, objP2]
for row in lstTable:
    print(row.to_string(), type(row))

# Test processing module - class FileProcessor
FileProcessor.save_data_to_file("EmployeeData.txt", lstTable)
lstFileData = FileProcessor.read_data_from_file("EmployeeData.txt")
lstTable.clear()
for line in lstFileData:
    lstTable.append(Employee(line[0], line[1], line[2].strip()))
for row in lstTable:
    print(row.to_string(), type(row))

# Test IO module - class EmployeeIO
EmployeeIO.print_menu_items()
EmployeeIO.print_current_list_items(lstTable)
print(EmployeeIO.input_employee_data())
print(EmployeeIO.input_menu_options())
    from ProcessingClasses import FileProcessor as FPClass
    from IOClasses import EmployeeIO as IOClass
else:
    raise Exception("This file was not created to be imported.")

empList = []  # list of employees

# On load, read data from text file and append each row to data list in context
readfile = FPClass.read_data_from_file("EmployeeData.txt")
for row in readfile:
    empList.append(EmployeeClass(row[0], row[1], row[2].strip()))

#  Operations
while True:
    IOClass.print_menu_items()  # display menu
    choice = IOClass.input_menu_options()  # determine choice
    if choice == "1":
        IOClass.print_current_list_items(empList)  # print data list in context
        continue
    elif choice == "2":
        dataAdded = IOClass.input_employee_data(
        )  # execute input_employee_data to determine data to be added
        empList.append(dataAdded)  # add employee data to data list in context
        continue
    elif choice == "3":
        FPClass.save_data_to_file("EmployeeData.txt",
                                  empList)  # save data list in context to file
        continue
    elif choice == "4":
        break  # exit program
strFileName = "EmployeeData.txt"
lstTable = []  # A list that acts as a 'table' of rows
strChoice = ""  # Captures the user option selection

# Main Body of Script  ---------------------------------------------------- #
# Load data from file into a list of employee objects when script starts
try:
    # Use this Processor function to read a text file and return a table of data
    lstTable = Fp.read_data_from_file(strFileName)  # read file data
    Eio.print_intro()  # print the script intro here
    while True:
        Eio.print_menu_items()  # print the menu here
        strChoice = Eio.input_menu_options()  # Get menu option
        # Process user's menu choice
        if strChoice.strip() == '1':  # Print the Employee Information
            Eio.print_current_list_items(
                lstTable)  # <<Print the list of employees here
            Eio.input_press_to_continue()  # send a message to the user
        elif strChoice == '2':  # Enter New Employee ID's and names
            while True:  # Use a While loop to allow for continued data entry
                # Use this Eio function to input a new Employee Id and Name Info
                strNewEmp = Eio.input_employee_data(
                    lstTable)  # Input New Employee Info here
                strEmpInfo = str(
                    strNewEmp
                )  # Took the returned Employee info and set to this string variable here
                empID, empFirstName, empLastName = strEmpInfo.split(
                    ",")  # Split out the various string pieces here
                # Print show the data for the new employee that was added
                print("New Employee Added: " + "ID: " + empID + " - " +
                      empFirstName + " " + empLastName)
                # Evaluate the user choice and exit loop if "n" in response
Beispiel #7
0
# Load data from file into a list of employee objects when script starts
lstFileData = FP.read_data_from_file(strFileName)  # load data from file
for line in lstFileData:
    lstOfEmployeeRows.append(E(line[0], line[1],
                               line[2].strip()))  # add data to list

# Show user a menu of options
while True:
    eIO.print_menu_items()

    # Get user's menu option choice
    strChoice = eIO.input_menu_options()

    # Show user current data in the list of employee objects
    if strChoice.strip() == '1':
        eIO.print_current_list_items(lstOfEmployeeRows)

    # Let user add data to the list of employee objects
    elif strChoice.strip() == '2':
        objEmployee = eIO.input_employee_data()
        lstOfEmployeeRows.append(objEmployee)  # add object to list

    # Let user save current data to file
    elif strChoice.strip() == '3':
        FP.save_data_to_file(strFileName, lstOfEmployeeRows)

    # Let user exit program
    elif strChoice.strip() == '4':
        break  # and exit

    else:
Beispiel #8
0
# data
file_name = "EmployeeData.txt"
empList = []
fileList = Fp.read_data_from_file(file_name)

# pull data from file into list
for row in fileList:
    empList.append(Emp(row[0], row[1], row[2].strip()))

# main script using modules
while True:
    # menu handling
    EmpIo.print_menu_items()
    usrCh = EmpIo.input_menu_options()

    # show current employees
    if usrCh == "1":
        EmpIo.print_current_list_items(empList)

    # user add employees
    elif usrCh == "2":
        empList.append(EmpIo.input_employee_data())

    # save current data to file
    elif usrCh == "3":
        Fp.save_data_to_file("EmployeeData.txt", empList)
        print("Data was saved")
    else:
        print("Exiting Program")
        break
Beispiel #9
0
# Main Body of Script  ---------------------------------------------------- #
# TODO: Add Data Code to the Main body (Done)
# Load data from file into a list of employee objects when script starts
lstOfEmployeeObjects = Fp.read_data_from_file(strFileName)
print(lstOfEmployeeObjects) #Prints statement to user

# Show user a menu of options
while True: # While loop to let user choose their menu option
    Eio.print_menu_items() #Calls print_menu_items

# Get user's menu option choice
    strChoice = Eio.input_menu_options() #Assigns the input of the menu option to strChoice

# Show user current data in the list of employee objects
    if strChoice.strip() == "1":
        Eio.print_current_list_items(lstOfEmployeeObjects) #Prints list of employee objects
        continue # Takes us back to the main menu

# Let user add data to the list of employee objects
    if strChoice.strip() == "2":
        while True: # While loop to let user add names
            try:
                objEmployee = Eio.input_employee_data() #Creates objEmployee
                lstOfEmployeeObjects.append(objEmployee) #Appends
                print(objEmployee.first_name + " " + #Prints statement to user
                      objEmployee.last_name +
                      " has been added." + #Let's user know the name has been added
                      str(objEmployee.employee_id) + "\n",
                      type(objEmployee))
            except Exception as e:
                print("\n", e, "\n")
Beispiel #10
0
# Data -------------------------------------------------------------------- #

# Main Body of Script ----------------------------------------------------- #
try:
    lstFileData = Fp.read_data_from_file(strFileName)  # read file data
    for row in lstFileData:  # put data in consumable format
        lstOfEmployees.append(Emp(row[0], row[1], row[2].strip()))

    while True:
        # Show user a menu of options
        Eio.print_menu_items()
        # Get user's menu option choice
        strChoice = Eio.input_menu_options()
        if strChoice.strip() == '1':
            # Print Employees listed in the file (if any)
            Eio.print_current_list_items(lstOfEmployees)
            continue
        elif strChoice.strip() == '2':
            # Let user add data to the list of employee objects
            lstOfEmployees.append(Eio.input_employee_data())
            continue
        elif strChoice.strip() == '3':
            # Let user save current data to file
            Fp.save_data_to_file(strFileName, lstOfEmployees)
            continue
        elif strChoice.strip() == '4':
            # Let user exit program
            break
        else:  # Add a catch all for invalid entries
            print("That option is not valid. Please select 1-4")
            continue
Beispiel #11
0
File = "EmployeeData.txt"
lstEmpObj = []
userChoice = ""

# Load data from file into a list of employee objects when script starts
fileData = Fp.read_data_from_file(File)
for line in fileData:
    lstEmpObj.append(Emp(line[0], line[1], line[2].strip()))

# Show user a menu of options
while True:
    Eio.print_menu_items()
    userChoice = Eio.input_menu_options()

    if userChoice.strip() == '1':  # Show current employee data
        Eio.print_current_list_items(lstEmpObj)

    elif userChoice.strip() == '2':  # Add new employee data
        lstEmpObj.append(Eio.input_employee_data())
        print('Employee added, press 3 to save this data to file!')

    elif userChoice.strip() == '3':  # Save employee data to File
        Fp.save_data_to_file(File, lstEmpObj)
        print("Employee data saved to file!")

    elif userChoice.strip() == '4':  # Exit Program
        print("Goodbye!")
        break

# Get user's menu option choice
# Show user current data in the list of employee objects
Beispiel #12
0
objP1 = Emp(1, "", "")
# Main Body of Script  ---------------------------------------------------- #
# Load data from file into a list of employee objects when script starts
currentList = P.read_data_from_file(strFileName)

choice = " "
while choice != "4":
    # Show user a menu of options
    Eio.print_menu_items()
    # Get user's menu option choice
    choice = Eio.input_menu_options()

    if choice == "1":
        # Show user current data in the list of employee objects
        if currentList != []:  # Check if there is any data in the list
            Eio.print_current_list_items(currentList)
            input("Press Enter to return to the Menu.")
        else:
            print("The list is currently empty.")
            input("Press Enter to return to the Menu.")
    elif choice == "2":
        # Let user add data to the list of employee objects
        try:  # Check for a user input that doesn't obey properties
            objP1 = Eio.input_employee_data()
            currentList.append(objP1)
        except UnboundLocalError:  # Let the user know they need to re-input their data
            print("Please try again.")
        input("Press Enter to return to the Menu.")
    elif choice == "3":
        # let user save current data to file
        x = P.save_data_to_file(strFileName, currentList)
Beispiel #13
0
# Load data from file into a list of employee objects when script starts

lst_file_data = Fp.read_data_from_file("EmployeeData.txt")
for row in lst_file_data:
    lst_emp_table.append(Emp(row[0],row[1],row[2].strip()))

# Show user a menu of options

while True:
    Eio.print_menu_items()
# Get user's menu option choice
    str_choice = Eio.input_menu_options()
    if str_choice == "1":
    # Show user current data in the list of employee objects
        Eio.print_current_list_items(lst_emp_table)
        continue
    elif str_choice == "2":
    # Let user add data to the list of employee objects
        lst_emp_table.append(Eio.input_employee_data())
        print("Employee Data Added.")
        continue
    elif str_choice == "3":
    # let user save current data to file
        Fp.save_data_to_file("EmployeeData.txt", lst_emp_table)
        print("Employee Data Saved.")
        continue
    elif str_choice == "4":
    # Let user exit program
        print("""
        *************************
Beispiel #14
0
        i[0], i[1], i[2].strip()))  # add employee object to list of objects

while True:
    # Show user a menu of options
    Eio.print_menu_items(
    )  # use EmployeeIO class of IOClasses Module to print menu

    # Get user's menu option choice, and check for errors
    try:  # check that code will run
        strChoice = Eio.input_menu_options()  # store user's selection
    except Exception as e:  # exception handled
        print(e)  # print error message

    # Show user current data in the list of employee objects
    if strChoice == '1':  # checks if user entered 1
        Eio.print_current_list_items(
            lstObjTable)  # print current list of employees
        input("Press [Enter] key to return to the menu. "
              )  # print message to continue

    # Let user add data to the list of employee objects
    elif strChoice == '2':  # checks if user entered 2
        try:  # check that code will run
            lstObjTable.append(Eio.input_employee_data()
                               )  # ask user to input new employee data
        except Exception:  # exception handles
            print("Something went wrong inputting employee data."
                  )  # custom error message
        print("New employee info input complete."
              )  # let user know employee data input is complete
        input("Press [Enter] key to return to the menu. "
              )  # print message to continue
strFileName = "EmployeeData.txt"
lstEmployeeData = []

# Main Body of Script  ---------------------------------------------------- #
# Load data from file into a list of employee objects when script starts
lstEmployeeData = Fp.read_data_from_file(strFileName)

while True:
    # Show user a menu of options
    Eio.print_menu_items()
    # Get user's menu option choice
    strChoice = Eio.input_menu_options()  # get menu option

    # Show user current data in the list of employee objects
    if strChoice == "1":
        Eio.print_current_list_items(lstEmployeeData)
    # Let user add data to the list of employee objects
    elif strChoice == "2":
        objEmp = Eio.input_employee_data()  # create new employee object
        lstEmployeeData.append(
            objEmp)  # append to existing list of employee objects
    # let user save current data to file
    elif strChoice == "3":
        Fp.save_data_to_file(strFileName, lstEmployeeData)
        print("Data Saved")
    # Let user exit program
    elif strChoice == "4":
        print("Ending Program")
        break
    else:
        print("Make a choice from 1 to 4")
Fp.save_data_to_file("EmployeeData.txt", lstTable)
lstFileData = Fp.read_data_from_file("EmployeeData.txt") # Load data from file into a list of employee objects when script starts
lstTable.clear()
for line in lstFileData:
    lstTable.append(Emp(line[0], line[1], line[2].strip()))
for row in lstTable:
    print(row.to_string(), type(row))

while (True):
    #Eio.print_current_list_items(lstTable) # Show current data in the list/table
    Eio.print_menu_items() # Show user a menu of options
    strChoice = Eio.input_menu_options()  # Get user's menu option choice

    if strChoice == '1':  # Add a new Task
        Eio.print_current_list_items(lstTable)# Show user current data in the list of employee objects
        continue # to show the menu

    elif strChoice == '2': #add new employee data
        print(Eio.input_employee_data()) # print new employee
        continue # to show the menu

    elif strChoice == '3':  # # let user save current data to file
        #p.save_data_to_file("PersonData.txt", lstTable)
        Fp.save_data_to_file("EmployeeData.txt", lstTable)
        lstFileData = Fp.read_data_from_file("EmployeeData.txt")
        lstTable.clear()
        for line in lstFileData:
            lstTable.append(Emp(line[0], line[1], line[2].strip()))
        for row in lstTable:
            print(row.to_string(), type(row))
Beispiel #17
0
# Main Body of Script  ---------------------------------------------------- #

# Read in current file and build a list of objects
lstFileData = Fp.read_data_from_file(strFileName)
lstOfEmployeeObjects.clear()
for line in lstFileData:
    lstOfEmployeeObjects.append(Emp(line[0], line[1], line[2].strip()))

while (True):
    eIO.print_menu_items()  # show user the menu
    strChoice = eIO.input_menu_options()

    # Process user's menu choice
    if strChoice.strip() == '1':  # Show Current list of products
        eIO.print_current_list_items(lstOfEmployeeObjects)
        continue  # to show the menu

    elif strChoice == '2':  # Add new employee data
        try:
            lstOfEmployeeObjects.append(eIO.input_employee_data())
        except Exception as e:
            raise print(e)
        continue  # to show the menu

    elif strChoice == '3':  # Save Data to File
        Fp.save_data_to_file(strFileName, lstOfEmployeeObjects)
        continue  # to show the menu

    elif strChoice == '4':  # Exit Program
        print("Goodbye!")
Beispiel #18
0
# Load data from file into a list of employee objects when script starts
lstFileData = Fp.read_data_from_file("EmployeeData.txt")
for row in lstFileData:
        lstEmployeeTable.append(Emp(row[0], row[1], row[2].strip()))

# Show user a menu of options
while True:
    Eio.print_menu_item()

# Get user's menu option choice
    strChoice = Eio.input_menu_options()

    # Show user current data in the list of employee objects
    if strChoice == "1":
        Eio.print_current_list_items(lstEmployeeTable)
        continue

    # Let user add data to the list of employee objects
    elif strChoice == "2":
        lstEmployeeTable.append(Eio.input_employee_data())
        continue

    # let user save current data to file
    elif strChoice == "3":
        if("y" == str(input("Would you like to save data to file? (y/n): ")).strip().lower()):
            Fp.save_data_to_file("EmployeeData.txt", lstEmployeeTable)
            input("Data was saved to file. Press the [Enter] key to return to menu.")
        else:
            input("New data was NOT saved to file. Press the [Enter] key to return to menu.")
        continue

# Main Body of Script  ---------------------------------------------------- #

# exceptions
class InvalidChoice(Exception):
    def __str__(self):
        return "Please choose from menu: option 1, 2, 3, or 4."


# initialize variables
strFileName = "EmployeeData.txt"

# Load data from file into a list of employee objects when script starts
lstEmployees = FileProcessor.read_data_from_file(strFileName)
EmployeeIO.print_current_list_items(lstEmployees)
# Show user a menu of options
while True:
    try:
        EmployeeIO.print_menu_items()
        intUserChoice = int(EmployeeIO.input_menu_options())
        if intUserChoice == 1:
            EmployeeIO.print_current_list_items(lstEmployees)
        elif intUserChoice == 2:
            newEmployee = EmployeeIO.input_employee_data()
            lstEmployees.append(newEmployee)
        elif intUserChoice == 3:
            FileProcessor.save_data_to_file(strFileName, lstEmployees)
        elif intUserChoice == 4:
            break
        else:
# RRoot,1.1.2030,Created started script
# RShip 12.16.20 used template to complete scrip.
# ---------------------------------------------------------- #
if __name__ == "__main__":
    from DataClasses import Employee as Emp
    from ProcessingClasses import FileProcessor as Fp
    from IOClasses import EmployeeIO as Eio
else:
    raise Exception("This file was not created to be imported")

# Test data module
objP1 = Emp(1, "Bob", "Smith")
objP2 = Emp(2, "Sue", "Jones")
lstTable = [objP1, objP2]
for row in lstTable:
    print(row.to_string(), type(row))

# Test processing module
Fp.save_data_to_file("EmployeeData.txt", lstTable)
lstFileData = Fp.read_data_from_file("EmployeeData.txt")
lstTable.clear()
for line in lstFileData:
    lstTable.append(Emp(line[0], line[1], line[2].strip()))
for row in lstTable:
    print(row.to_string(), type(row))

# Test IO classes
Eio.print_menu_items()
Eio.print_current_list_items(lstTable)
print(Eio.input_employee_data())
print(Eio.input_menu_options())
Beispiel #21
0
# Main Body of Script  ---------------------------------------------------- #
# TODO: Add Data Code to the Main body

# Load data from file into a list of employee objects when script starts
EmployeeList = DatabaseProcessor.stringlist_to_employeelist(
    FileProcessor.read_data_from_file(datafilename))

while True:
    # Show user a menu of options
    EmployeeIO.print_menu_items()
    # Get user's menu option choice
    userpicked = EmployeeIO.input_menu_options()

    if userpicked == "1":
        # Show user current data in the list of employee objects
        EmployeeIO.print_current_list_items(EmployeeList)
    elif userpicked == "2":
        # Let user add data to the list of employee objects
        EmpObj = EmployeeIO.input_employee_data()
        EmployeeList.append(EmpObj)
    elif userpicked == "3":
        # let user save current data to file
        DidIWork = FileProcessor.save_data_to_file(
            datafilename,
            DatabaseProcessor.employeelist_to_listforcsv(EmployeeList))

        if DidIWork:
            print("Text File saved!\n")
        else:
            print("Error saving text file.\n")
    elif userpicked == "4":