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(): ...@@ -13,9 +13,12 @@ def generate_daily_report():
# Generate the daily report # Generate the daily report
report_path = report_generator.create_excel_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 # Send the email with the report
# please comment out if you are running the create_report.py file without a email method. # 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 return report_path
......
template_file: D:\vision_utilities\vision_utilities\report_generator\templates\daily_report_jk_template.xlsx 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 # logo_image: path/to/logo.png
cameras: cameras:
...@@ -15,7 +16,7 @@ cameras: ...@@ -15,7 +16,7 @@ cameras:
- camera_name: Packer 7 - camera_name: Packer 7
packer_name: Packer - 7 packer_name: Packer - 7
email: email:
subject: Daily Report subject: Daily Report
......
...@@ -3,4 +3,5 @@ pymongo==3.11.4 ...@@ -3,4 +3,5 @@ pymongo==3.11.4
PyYAML==6.0 PyYAML==6.0
openpyxl==3.1.2 openpyxl==3.1.2
requests==2.29.0 requests==2.29.0
python-dotenv==1.0.0 python-dotenv==1.0.0
\ No newline at end of file pillow==9.5.0
\ No newline at end of file
...@@ -73,10 +73,13 @@ class DailyReportGenerator: ...@@ -73,10 +73,13 @@ class DailyReportGenerator:
current_time = datetime.now() 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 # Calculate the previous day's date
previous_day = current_time - timedelta(days=1) previous_day = current_time - timedelta(days=1)
report_date = previous_day.strftime("%Y-%m-%d") 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) wb = load_workbook(self.template_file)
sheet = wb.active sheet = wb.active
......
...@@ -75,10 +75,13 @@ class DailyReportGenerator: ...@@ -75,10 +75,13 @@ class DailyReportGenerator:
current_time = datetime.now() 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 # Calculate the previous day's date
previous_day = current_time - timedelta(days=1) previous_day = current_time - timedelta(days=1)
report_date = previous_day.strftime("%Y-%m-%d") 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) wb = load_workbook(self.template_file)
sheet = wb.active sheet = wb.active
...@@ -136,9 +139,26 @@ class DailyReportGenerator: ...@@ -136,9 +139,26 @@ class DailyReportGenerator:
# Return the absolute path of the generated report file # Return the absolute path of the generated report file
file_path = os.path.abspath(report_file) file_path = os.path.abspath(report_file)
return file_path 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): def get_receiver_emails(self):
# Connect to MongoDB and retrieve the email addresses from the collection # Connect to MongoDB and retrieve the email addresses from the collection
client = MongoClient(os.environ["MONGO_CLIENT"]) 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