Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JK_Report
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vaisakh.nair
JK_Report
Commits
0e04ae63
Commit
0e04ae63
authored
May 16, 2023
by
vaisakh.nair
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new changes to dockerfile
parent
cfa9e671
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
70 additions
and
51 deletions
+70
-51
.env
.env
+10
-6
Dockerfile
Dockerfile
+1
-4
app.py
app.py
+6
-1
config.yml
config.yml
+9
-0
daily_report.xlsx
daily_report.xlsx
+0
-0
requirements.txt
requirements.txt
+2
-1
utils/__pycache__/create_report.cpython-38.pyc
utils/__pycache__/create_report.cpython-38.pyc
+0
-0
utils/__pycache__/create_report_sample.cpython-38.pyc
utils/__pycache__/create_report_sample.cpython-38.pyc
+0
-0
utils/create_report.py
utils/create_report.py
+1
-1
utils/create_report_sample.py
utils/create_report_sample.py
+41
-38
No files found.
.env
View file @
0e04ae63
...
...
@@ -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
Dockerfile
View file @
0e04ae63
...
...
@@ -10,9 +10,6 @@ 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>
...
...
app.py
View file @
0e04ae63
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
()
...
...
config.yml
View file @
0e04ae63
...
...
@@ -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
daily_report.xlsx
0 → 100644
View file @
0e04ae63
File added
requirements.txt
View file @
0e04ae63
...
...
@@ -2,3 +2,4 @@ pandas==1.1.5
pymongo
==3.11.4
PyYAML
==6.0
openpyxl
==3.1.2
requests
==2.29.0
utils/__pycache__/create_report.cpython-38.pyc
View file @
0e04ae63
No preview for this file type
utils/__pycache__/create_report_sample.cpython-38.pyc
0 → 100644
View file @
0e04ae63
File added
utils/create_report.py
View file @
0e04ae63
...
...
@@ -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
...
...
utils/create_report_sample.py
View file @
0e04ae63
...
...
@@ -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
...
...
@@ -156,34 +157,36 @@ class DailyReportGenerator:
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment