provide python code for a program that can be run daily which asks a user what they worked on each day logging the collected information. additionally the program can be asked to make a report for a month using the collected data where the output is well organized based on patterns in the data in the RTF format
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Sure! Here's a Python code that allows a user to log their daily work and generate a monthly report in RTF format:
python
import datetime
from docx import Document
def log_work():
today = datetime.date.today()
work_done = input(f"Enter your work for {today}: ")
with open("work_log.txt", "a") as file:
file.write(f"{today}: {work_done}\n")
def generate_report():
month = input("Enter the month (1-12): ")
year = input("Enter the year: ")
start_date = datetime.date(int(year), int(month), 1)
end_date = start_date + datetime.timedelta(days=31)
report = Document()
report.add_heading(f"Work Report - {start_date.strftime('%B %Y')}", level=1)
with open("work_log.txt", "r") as file:
for line in file:
date_str, work_done = line.strip().split(": ")
date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
if start_date <= date <= end_date:
report.add_paragraph(f"{date.strftime('%Y-%m-%d')}: {work_done}")
report.save("work_report.rtf")
print("Report generated successfully!")
while True:
print("1. Log work")
print("2. Generate monthly report")
print("3. Exit")
choice = input("Enter your choice (1-3): ")
if choice == "1":
log_work()
elif choice == "2":
generate_report()
elif choice == "3":
break
else:
print("Invalid choice. Please try again.")
Make sure to install the python-docx library by running pip install python-docx before running the code.
This code creates a menu where the user can choose to log their work or generate a monthly report. The work logs are stored in a text file (work_log.txt) and the monthly report is generated in RTF format (work_report.rtf). The report includes all the work logged for a given month.