Digital Employee Registrar, python script can be used to record employee information and retrieve that information by providing reference input like Day, Working Hour and so on.
This script creates a binary file called ‘data.bin’ on your script directory for maintaining a record and it is used while recording and retrieving data during execution of the script. This script is tested under python 2.7 and worked fine. To make it work on your system change shebang line and provide an appropriate interpreter location and make sure you have python version 2.7x installed in your system otherwise simply precede ‘script name’ with ‘python’ and make sure you provide execute permission for this script.
Module Used:
- Pickle
- Os
Python Code:
''' Author: Ramchandra Shahi Thakuri Date: 13/09/18 ''' import pickle import os #welcome message os.system("clear") print("\t\t\t\t\t\t\tDigital Employee Registar\n\n") def record(): global eplDetail global entryNo name = '' address = '' contact = int() day = '' def readEntry(): for count in range(0, entryNo): print(str(count + 1) + ")") eplDetail[0].append(getValData(name, "string", "Provide Employee Name:")) eplDetail[1].append(getValData(address, "string", "Address:")) eplDetail[2].append(getValData(contact, "num", "Contact:")) eplDetail[3].append(getValData(day, "string", "Working Day:")) eplDetail[4].append(getValData(name, "string", "Working Hour(HH:MM):")) print("\n") def getValData(var, dataType, inPrompt): if dataType == 'string': while 1: var = raw_input(inPrompt) try: if int(var): print("\nInvalid Input\nInput it again\n\n") except ValueError: break else: while 1: var = raw_input(inPrompt) try: if int(var): if len(var) < 9: print("\nNumber Can't be less than 9 digit\nPlease Enter Valid Contact Number\n\n") continue break except ValueError: print("\nInvalid Input\nInput it again\n\n") continue if inPrompt == "Working Day:": while (var[0].upper() + var[1:]) not in ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday']: print("\nInvalid Day\nPlease Provide Valid Day\n\n") var = raw_input(inPrompt) return var try: with open("data.bin", "rb") as read: eplDetail = pickle.load(read) read.close() update = raw_input("Do you want to update entry [y/n]:") if update is 'y': #lets update by day entryNo=(int(raw_input("How many entry to you want to update:"))) with open("data.bin", "rb+") as update: readEntry() pickle.dump(eplDetail, update) update.close() else: None except IOError: entryNo = int(input("How many entry do you want to record:")) print("\n") eplDetail = [[], [], [], [], []] readEntry() with open("data.bin", "wb") as write: pickle.dump(eplDetail, write) write.close() def displayRecord(): #lets display record by day userKey = '' while userKey != 'n': chooseDay = raw_input("Provide Search Day:") while (chooseDay[0].upper() + chooseDay[1:]) not in ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Friday', 'Saturday']: print("\n" + str(chooseDay[0].upper() + chooseDay[1:]) +" Invalid Day\nPlease Provide Valid Day\n\n") chooseDay = raw_input("Please Enter Valid Day:") check = 0 print("\nAvailabe employees for " + chooseDay.upper() + ":\n") track = 1 for count in range(0, len(eplDetail[3])): if eplDetail[3][count].upper()== chooseDay.upper(): print("\n\n" + str(track) + ")") print("Employee Name: " + eplDetail[0][count].upper() + "\n") print("Address: " + eplDetail[1][count].upper() + "\n") print("Contact: " + str( eplDetail[2][count]) + "\n") print("Working Hour: " + str(eplDetail[4][count]) + "\n") check = 1 track += 1 if check != 1: print("Sorry !, no employee availabe\n\n") userKey = raw_input("Do you still want to search for next day [y/n]:") print("\n") record() displayRecord() print("\nThank you for using Digital Employee Registar By Ramchandra Shahi Thakuri\n\n")
Note: This script is written by Ramchandra Shahi Thakuri you can visit his personal site i.e www.rcthakuri.com.np to see his awesome works.