You need to sign in or sign up before continuing.
Commit 0e04ae63 authored by vaisakh.nair's avatar vaisakh.nair 🎯

new changes to dockerfile

parent cfa9e671
......@@ -6,9 +6,13 @@ MONGO_CLIENT=mongodb://admin:iLens%241234@192.168.3.181:2717/admin?connectTimeou
MONGO_PORT=2717
MONGO_DATABASE=ilens_ai
MONGO_COLLECTION=eventLogs
MONGO_COLLECTION_EMAIL=
SMTP_HOST=
SMTP_PORT=
SMTP_USERNAME=
SMTP_PASSWORD=
SENDER_EMAIL=
\ No newline at end of file
URL_WITH_ATTACH=https://cloud.ilens.io/sms-util/api/v1/eim/email/form/send
URL_WITHOUT_ATTACH=https://cloud.ilens.io/sms-util/api/v1/eim/email/send
AUTHORIZATION=Basic QWxsR29vZE5hbWVzUkdvbmU6Y29tQlJBTlNlQU50YW1hc0ViSUNhUGVD
FROM_ADDRESS=no-reply@ilens.io
MONGO_COLLECTION_EMAIL=email_ids
# SMTP_HOST=
# SMTP_PORT=
# SMTP_USERNAME=
# SMTP_PASSWORD=
# SENDER_EMAIL=
\ No newline at end of file
......@@ -10,11 +10,8 @@ COPY . /app
# Install the project dependencies
RUN pip install -r requirements.txt
# Set the working directory to the app folder
WORKDIR /app/utils
# Expose the port on which your application runs (if needed)
# EXPOSE <port_number>
# Define the command to run your application
CMD ["python", "../app.py"]
CMD ["python", "../app.py"]
\ No newline at end of file
import logging
from utils.create_report import DailyReportGenerator
from utils.create_report_sample import DailyReportGenerator
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def generate_daily_report():
# Create an instance of DailyReportGenerator
report_generator = DailyReportGenerator()
......@@ -12,8 +13,12 @@ def generate_daily_report():
# Generate the daily report
report_path = report_generator.create_excel_report()
# Send the email with the report
report_generator.send_email_from_ut(filepath=report_path)
return report_path
if __name__ == "__main__":
try:
report_path = generate_daily_report()
......
......@@ -14,3 +14,12 @@ cameras:
packer_name: Packer 6
- camera_name: camera_47
packer_name: Packer 7
subject: Daily Report
body: |
Dear recipient,
Please find attached the daily report for your review.
Thank you.
\ No newline at end of file
pandas==1.1.5
pymongo==3.11.4
PyYAML==6.0
openpyxl==3.1.2
\ No newline at end of file
openpyxl==3.1.2
requests==2.29.0
......@@ -76,7 +76,7 @@ class DailyReportGenerator:
# 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}.xlsx"
wb = load_workbook(self.template_file)
sheet = wb.active
......
......@@ -8,11 +8,12 @@ import yaml
from dotenv import load_dotenv
from collections import defaultdict
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
# from email.mime.multipart import MIMEMultipart
# from email.mime.text import MIMEText
# from email.mime.base import MIMEBase
# from email import encoders
import requests
import logging
load_dotenv(dotenv_path='.env')
......@@ -81,7 +82,7 @@ class DailyReportGenerator:
# 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}.xlsx"
wb = load_workbook(self.template_file)
sheet = wb.active
......@@ -154,36 +155,38 @@ class DailyReportGenerator:
emails.append(document["email"])
return emails
def send_email(self, report_path):
# Email configuration
smtp_host = os.environ["SMTP_HOST"]
smtp_port = os.environ["SMTP_PORT"]
smtp_username = os.environ["SMTP_USERNAME"]
smtp_password = os.environ["SMTP_PASSWORD"]
sender_email = os.environ["SENDER_EMAIL"]
receiver_emails = self.get_receiver_emails() # Fetch receiver email addresses
# Create a multipart message
msg = MIMEMultipart()
msg["From"] = sender_email
msg["To"] = ", ".join(receiver_emails)
msg["Subject"] = "Daily Report"
# Attach the report file
attachment = open(report_path, "rb")
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header("Content-Disposition", f"attachment; filename= {report_path}")
msg.attach(part)
# Send the email
with smtplib.SMTP(smtp_host, smtp_port) as smtp:
smtp.starttls()
smtp.login(smtp_username, smtp_password)
smtp.send_message(msg)
# Close the attachment file
attachment.close()
def send_email_from_ut(self,filename="daily_report", filepath=None):
logging.info("Sending email to {}".format(self.get_receiver_emails()))
payload = dict()
payload['from_name'] = os.environ["FROM_ADDRESS"]
payload['receiver_list'] = self.get_receiver_emails()
payload['subject'] = self.config['subject']
payload['content'] = self.config['body']
headers = {'authorization': os.environ["AUTHORIZATION"]}
count = 0
while count < 3:
try:
if filename and filepath:
files = [('attachments', (filename, open(filepath, 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))]
# print(payload)
# print(os.environ["URL_WITH_ATTACH"])
response = requests.request("POST", os.environ["URL_WITH_ATTACH"], data=payload,
headers=headers, files=files, timeout=10)
print(response.text)
logging.info(f"Response status code for request is: {response.status_code}")
if response.status_code == 200:
return True
else:
response = requests.request("POST", os.environ["URL_WITHOUT_ATTACH"], json=payload,
headers=headers, timeout=10)
logging.info(f"Response status code for request is: {response.status_code}")
if response.status_code == 200:
return True
except Exception as e:
logging.error(e)
count += 1
return False
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