Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i have issue with the code #98

Open
fahd889 opened this issue Jun 13, 2023 · 0 comments
Open

i have issue with the code #98

fahd889 opened this issue Jun 13, 2023 · 0 comments

Comments

@fahd889
Copy link

fahd889 commented Jun 13, 2023

the error

Traceback (most recent call last):
File "C:/Users/Fa/Desktop/test1.py", line 2, in
from docx import Document
ModuleNotFoundError: No module named 'docx'

the code ::

import datetime
from docx import Document

def create_shift_schedule(start_date, end_date, employees):
"""
Creates a table in Word with the automatically redistributed shifts.

Args:
start_date: The start date of the schedule.
end_date: The end date of the schedule.
employees: A list of employee names.

Returns:
A table in Word with the automatically redistributed shifts.
"""

Create a list of dates.

dates = []
for day in range(datetime.date.fromisoformat(start_date), datetime.date.fromisoformat(end_date) + 1):
dates.append(day)

Create a Word document.

doc = Document()

Create a table in the Word document.

table = doc.add_table(rows=len(dates), cols=len(employees) + 1)

Populate the table with the dates and employee names.

for i, date in enumerate(dates):
for j, employee in enumerate(employees):
table.cell(i, j).text = date
table.cell(i, j + 1).text = employee

Get the list of employees on vacation.

vacation_employees = []
for employee in employees:
if employee in vacation_employees:
continue
vacation_start_date = input("Enter the start date of the employee's vacation (YYYY-MM-DD): ")
vacation_end_date = input("Enter the end date of the employee's vacation (YYYY-MM-DD): ")
vacation_employees.append((employee, vacation_start_date, vacation_end_date))

Exclude employees on vacation from the shift schedule.

for employee, vacation_start_date, vacation_end_date in vacation_employees:
for i in range(len(dates)):
if dates[i] >= vacation_start_date and dates[i] <= vacation_end_date:
table.cell(i, j + 1).text = ""

Save the Word document.

doc.save("shift_schedule.docx")

if name == "main":

Get the start and end dates from the user.

start_date = input("Enter the start date (YYYY-MM-DD): ")
end_date = input("Enter the end date (YYYY-MM-DD): ")

Get the list of employee names from the user.

employees = input("Enter the list of employee names (separated by commas): ").split(",")

Create the shift schedule.

create_shift_schedule(start_date, end_date, employees)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant