Commit 414de4e0 authored by vaisakh.nair's avatar vaisakh.nair 🎯

new logic changes and saving to folder added

parent 61bda7f1
......@@ -13,9 +13,12 @@ def generate_daily_report():
# Generate the daily report
report_path = report_generator.create_excel_report()
# saving file locally in one more specified file path
report_generator.save_report_locally(filepath=report_path)
# Send the email with the report
# please comment out if you are running the create_report.py file without a email method.
report_generator.send_email_from_ut(filepath=report_path)
#report_generator.send_email_from_ut(filepath=report_path)
return report_path
......
template_file: D:\vision_utilities\vision_utilities\report_generator\templates\daily_report_jk_template.xlsx
folder_path: D:\jk_reports\daily_reports
# logo_image: path/to/logo.png
cameras:
......
......@@ -4,3 +4,4 @@ PyYAML==6.0
openpyxl==3.1.2
requests==2.29.0
python-dotenv==1.0.0
pillow==9.5.0
\ No newline at end of file
......@@ -73,10 +73,13 @@ class DailyReportGenerator:
current_time = datetime.now()
# Generate a unique identifier (e.g., timestamp)
unique_id = current_time.strftime("%Y%m%d%H%M%S%f")
# Calculate the previous day's date
previous_day = current_time - timedelta(days=1)
report_date = previous_day.strftime("%Y-%m-%d")
report_file = f"daily_report_{report_date}.xlsx"
report_file = f"daily_report_{report_date}_{unique_id}.xlsx"
wb = load_workbook(self.template_file)
sheet = wb.active
......
......@@ -75,10 +75,13 @@ class DailyReportGenerator:
current_time = datetime.now()
# Generate a unique identifier (e.g., timestamp)
unique_id = current_time.strftime("%Y%m%d%H%M%S%f")
# Calculate the previous day's date
previous_day = current_time - timedelta(days=1)
report_date = previous_day.strftime("%Y-%m-%d")
report_file = f"daily_report_{report_date}.xlsx"
report_file = f"daily_report_{report_date}_{unique_id}.xlsx"
wb = load_workbook(self.template_file)
sheet = wb.active
......@@ -136,9 +139,26 @@ class DailyReportGenerator:
# Return the absolute path of the generated report file
file_path = os.path.abspath(report_file)
return file_path
def save_report_locally(self, filepath):
# Create the 'daily_reports' folder if it doesn't exist
folder_path = self.config['folder_path']
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Get the filename from the filepath
filename = os.path.basename(filepath)
# Save the report file in the 'daily_reports' folder
destination = os.path.join(folder_path, filename)
os.rename(filepath, destination)
return destination
def get_receiver_emails(self):
# Connect to MongoDB and retrieve the email addresses from the collection
client = MongoClient(os.environ["MONGO_CLIENT"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment