Untitled
unknown
plain_text
2 years ago
5.2 kB
7
Indexable
H.R. App with open("employees_data.txt", "r") as obj: data_list = obj.readlines() user_list = [] for a in data_list: splt = a.split('|') user = splt[0] user_list.append(user) class Employee: def __init__(self, first, last, joining_date, current_pay, post, exp_in_years): print(f"Creating Employee Object for {first}...") self.first = first self.last = last self.joining_date = joining_date self.current_pay = current_pay self.post = post self.exp_in_years = exp_in_years # variable creation on the fly # emp id = 00001 self.email = first + '.' + last + '@company.com' self.pswd = first.lower()[0] + str(self.last.upper()) + "123@pass" self.status = "Lateral" if self.exp_in_years else "Fresher" print(f"Employee Object is Created for {first}") def save_data(self): print(f"Employee Details for {self.first} are stored successfully !") with open("employees_data.txt", 'a') as obj: obj.write(f"{self.first}|{self.last}|{self.joining_date}|{str(self.current_pay)}|{self.post}|\ {self.status}|{str(self.exp_in_years)}|{self.email}|{self.pswd}\n") print('''Welcome to HR Applications: 1. Add New Employee 2. Get Employee Info 3. Update Employee : salary, post 4. Terminate an Employee 5. Appraisals''') ask = int(input("What you want to do (Enter only serial no.) : ")) if ask == 1: while ask != "n": first = input('Enter Employee first name: ') last = input('Enter Employee last name: ') joining_date = input('Enter Employee joining date: ') current_pay = int(input('Enter Employee pay: ')) post = input('Enter Employee post: ') exp_in_years = int(input('Experience in years: ')) emp = Employee(first, last, joining_date, current_pay, post, exp_in_years) emp.save_data() ask = input("Do you want to add other Employee(y/n): ") if ask == 2: ask_for_user = input("Which employee's info you want to see: ") num = 1 if ask_for_user not in user_list: print(f"Sorry no record found for {ask_for_user}.") else: cnt = user_list.count(ask_for_user) print(f"There are {cnt} records found =>.") for i in data_list: s = i.split("|") user = s[0] if user == ask_for_user: print(num, ".", i) num += 1 if ask == 3: ask_update = input("Enter the employee name to update the salary: ") num = 1 if ask_update not in user_list: print(f"Sorry, no record found for {ask_update}.") else: cnt = user_list.count(ask_update) print(f"There are {cnt} records found.") ask1 = input("What you want to update - salary(s), post(p): ") if ask1 == 's': for i in range(len(data_list)): s = data_list[i].split("|") user = s[0] if user == ask_update: print(num, ".", data_list[i]) updated_salary = input("Enter updated salary: ") s[3] = updated_salary data_list[i] = "|".join(s) num += 1 with open("employees_data.txt", "w") as update_obj: update_obj.writelines(data_list) print("Salary updated successfully!") if ask1 == "p": for i in range(len(data_list)): s = data_list[i].split("|") user = s[0] if user == ask_update: print(num, ":", data_list[i]) updated_post = input("Enter updated post: ") s[4] = updated_post data_list[i] = "|".join(s) num += 1 with open("employees_data.txt", "w") as update_obj: update_obj.writelines(data_list) print("Post updated successfully!") if ask == 4: ask_delete = input("Enter the employee name that you want to terminate: ") if ask_delete not in user_list: print(f"No data found for {ask_delete}") else: cnt = user_list.count(ask_delete) print(f"There are {cnt} records found.") ask_post = input("Enter Employee's post name: ") for i in data_list: s = i.split("|") user = s[0] post = s[4] if user == ask_delete and post == ask_post: print(i) ask = input("Do you want to delete this (y/n): ") if ask == 'y': index_to_delete = user_list.index(ask_delete) # adding data into a terminated user's list for future with open("terminated_employees.txt", "a") as obj: obj.write(data_list[index_to_delete]) del data_list[index_to_delete] with open("employees_data.txt", "w") as update_obj: update_obj.writelines(data_list) print(f"{ask_delete} deleted successfully.") else: pass if ask == 5: print("*** This functionality is coming soon. ***")
Editor is loading...