-
Notifications
You must be signed in to change notification settings - Fork 0
/
Front_end_and_email_sender.py
138 lines (95 loc) · 3.87 KB
/
Front_end_and_email_sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#Importing all the libraries
# This for building the front end for user interaction
import streamlit as st
import pandas as pd
#datetime and scheduler were used to run a function everyday on a given particular time
# import schedule
import datetime as dt
#To send an email to the user with todays dashboard as a png image
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email import encoders
import smtplib
#For reading image files
from PIL import Image
import os
#Taking user name from the user
# user_name = st.text_input('Enter you Name')
#Title for the web app
st.markdown("<h1 style='text-align: center; color: white;'>GRAPHICS CARD PICKER</h1>", unsafe_allow_html=True)
st.markdown('#')
#Title of the table
st.subheader('Table generator based on price')
df = pd.read_excel('cleaned_data.xlsx')
max_price = df['Price'].max()
#Displaying the image with the user interaction
with st.expander("Click to expand"):
user_price = st.slider(label = 'Slide to increase/decrease the price and get all graphic cards below/equal to the price provided',max_value= int(max_price),step = 5000, value = 10000)
return_table = df.loc[df['Price']<=user_price]
st.table(return_table)
st.markdown('#')
#Title for the report generator
st.subheader('Report Generator')
#To display the dashboard to the user
if st.button(label = 'Press the button to get a report online'):
with st.spinner('Wait for it...'):
image_output = Image.open('report.png')
st.image(image_output)
st.write('"Here are todays report on the graphic cards"')
#Part of the code to send and email to the user
st.markdown('#')
st.subheader('Subscribe to get the reports automatically sent to you everyday!')
user_email = st.text_input('Enter your Email')
#Button to intiate the email to the user
if st.button(label = 'Press the button to get a report to your email '):
with st.spinner('Wait for it...'):
# Python code to illustrate Sending mail with attachments
# from your Gmail account
# libraries to be imported
email_user = user_email
my_secret2 = email_user
fromaddr = 'trustthetechie@gmail.com'
toaddr = my_secret2
# instance of MIMEMultipart
msg = MIMEMultipart()
# storing the senders email address
msg['From'] = fromaddr
# storing the receivers email address
msg['To'] = toaddr
# storing the subject
msg['Subject'] = "Subject of the Mail"
# string to store the body of the mail
body = "Body_of_the_mail"
# attach the body with the msg instance
msg.attach(MIMEText(body, 'plain'))
# open the file to be sent
filename = 'report.png'
attachment = Image.open('report.png')
# instance of MIMEBase and named as p
# p = MIMEBase('application', 'octet-stream')
# To change the payload into encoded form
# p.set_payload((attachment).read())
# encode into base64
# encoders.encode_base64(p)
# p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
# attach the instance 'p' to instance 'msg'
with open('report.png', 'rb') as f:
img_data = f.read()
image = MIMEImage(img_data, name=os.path.basename('report.png'))
msg.attach(image)
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for security
s.starttls()
# Authentication
s.login(fromaddr, 'pass@ord')
# # Converts the Multipart msg into a string
text = msg.as_string()
# sending the mail
s.sendmail(fromaddr, toaddr, text)
# terminating the session
s.quit()
with st.spinner('Wait for it...'):
st.success('Email has been sent to you!')