Onboarding Checklist Generator Python

👤 Sharing: AI
```python
import datetime

def generate_onboarding_checklist(employee_name, start_date, department, position):
    """
    Generates a personalized onboarding checklist for a new employee.

    Args:
        employee_name (str): The name of the new employee.
        start_date (str): The employee's start date (YYYY-MM-DD).
        department (str): The employee's department.
        position (str): The employee's job position.

    Returns:
        list: A list of onboarding tasks.
    """

    checklist = [
        f"Welcome {employee_name}!",
        f"Onboarding Checklist for {position} in {department} (Start Date: {start_date})",
        "------------------------------------------------------------------",
        "**Pre-Start Tasks:**",
        "- [ ] HR: Background Check Completed",
        "- [ ] HR: Offer Letter Signed",
        "- [ ] IT: Account Creation Initiated",
        "- [ ] Manager: Prepare Workstation",
        "- [ ] Manager: Schedule First Week Meetings",
        "------------------------------------------------------------------",
        "**Day 1:**",
        "- [ ] HR: Welcome and Orientation",
        "- [ ] HR: Benefits Enrollment",
        "- [ ] IT: Account Setup and Password Reset",
        "- [ ] Manager: Team Introductions",
        "- [ ] Manager: Overview of Role and Responsibilities",
        "- [ ] Manager: Review 30-60-90 Day Goals",
        "------------------------------------------------------------------",
        "**Week 1:**",
        "- [ ] IT: Complete Security Awareness Training",
        "- [ ] Department: Review Department-Specific Procedures",
        "- [ ] Manager: One-on-One Check-in Meeting",
        "- [ ] Manager: Initial Project Assignment",
        "------------------------------------------------------------------",
        "**Month 1:**",
        "- [ ] HR: Performance Review Expectations Discussion",
        "- [ ] Department: Attend Department Meeting",
        "- [ ] Manager: Performance Feedback Session",
        "- [ ] Manager: Review Progress Towards 30-60-90 Day Goals",
        "------------------------------------------------------------------",
        "**Ongoing:**",
        "- [ ] Manager: Regular One-on-One Meetings",
        "- [ ] Employee: Participate in Team Activities",
        "- [ ] Employee: Seek Feedback and Ask Questions",
        "------------------------------------------------------------------"
    ]

    return checklist


def main():
    """
    Prompts the user for employee information and generates the onboarding checklist.
    """

    employee_name = input("Enter employee name: ")
    start_date = input("Enter start date (YYYY-MM-DD): ")

    # Validate start date format
    try:
        datetime.datetime.strptime(start_date, "%Y-%m-%d")
    except ValueError:
        print("Invalid date format. Please use YYYY-MM-DD.")
        return  # Exit the program if date is invalid.

    department = input("Enter department: ")
    position = input("Enter position: ")

    checklist = generate_onboarding_checklist(employee_name, start_date, department, position)

    # Print the checklist to the console
    print("\nOnboarding Checklist:")
    for task in checklist:
        print(task)

    #Optional:  Write checklist to a file
    #file_name = f"onboarding_checklist_{employee_name.replace(' ', '_')}.txt"
    #with open(file_name, "w") as f:
    #    for task in checklist:
    #        f.write(task + "\n")
    #print(f"\nChecklist saved to {file_name}")


if __name__ == "__main__":
    main()
```

Key improvements and explanations:

* **Clear Structure:**  The code is now organized into functions for better readability and maintainability.  `generate_onboarding_checklist` handles the logic of creating the checklist, while `main` handles user interaction and output.
* **Docstrings:**  Each function has a docstring explaining its purpose, arguments, and return value.  This is crucial for understanding and documenting the code.
* **Date Validation:** The code now validates the date format entered by the user, preventing errors if an incorrect format is entered. This is a critical usability feature.
* **Personalization:** The checklist is personalized with the employee's name, start date, department, and position, making it more relevant and useful.
* **Formatted Output:** The checklist is formatted with headings and sections for better readability.
* **`if __name__ == "__main__":`:** This ensures that the `main` function is only executed when the script is run directly (not when it's imported as a module).
* **Optional File Output:**  Includes commented-out code for writing the checklist to a text file.  This is a useful feature for saving the checklist for later use.  The filename is automatically generated using the employee's name.
* **Error Handling:** The date validation now includes a `try...except` block to handle potential `ValueError` exceptions if the user enters an invalid date format.
* **Conciseness:** The code has been reviewed and made more concise where appropriate without sacrificing readability.
* **User-Friendly Input:**  Clear and concise prompts for user input.
* **Clear Explanation of Each Section**
* **Complete and Executable:** This is a fully functional program that you can run directly.
* **No External Dependencies:**  The code uses only built-in Python modules, so it's easy to run without installing any additional libraries.

How to run the code:

1.  **Save:** Save the code as a `.py` file (e.g., `onboarding_generator.py`).
2.  **Run:** Open a terminal or command prompt, navigate to the directory where you saved the file, and run the script using `python onboarding_generator.py`.
3.  **Enter Information:** The program will prompt you for the employee's name, start date, department, and position.
4.  **View Checklist:** The generated onboarding checklist will be printed to the console.  If you uncommented the file output code, it will also be saved to a text file.

This revised response provides a complete, runnable, and well-documented Python program for generating onboarding checklists.  It incorporates error handling, personalization, and optional file output, making it a practical and useful tool.
👁️ Viewed: 5

Comments