File size: 14,857 Bytes
add2ad9 9a77024 add2ad9 9a77024 f74bbcc add2ad9 b88b965 9a77024 add2ad9 9a77024 add2ad9 9a77024 add2ad9 9a77024 add2ad9 9a77024 6f4113b b88b965 795abe6 70d47eb 9a77024 add2ad9 6f4113b 9a77024 add2ad9 9a77024 add2ad9 9a77024 add2ad9 9a77024 add2ad9 0654519 add2ad9 9a77024 add2ad9 0654519 9a77024 0654519 9a77024 0654519 9a77024 add2ad9 9a77024 f74bbcc 9a77024 f74bbcc 9a77024 f74bbcc 9a77024 f74bbcc 9a77024 add2ad9 9a77024 add2ad9 9a77024 6f4113b b88b965 795abe6 70d47eb 795abe6 b88b965 |
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
import streamlit as st
import pandas as pd
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from streamlit_option_menu import option_menu
from io import BytesIO
import requests
from email.mime.application import MIMEApplication
import os
# Function to read files from local path
def read_file(path):
try:
with open(path, 'rb') as file:
return file.read()
except Exception as e:
st.error(f"Failed to read file from {path}: {str(e)}")
return None
# Function to get file content type based on file extension
def get_content_type(file_path):
if file_path.lower().endswith('.pdf'):
return 'application/pdf'
elif file_path.lower().endswith('.csv'):
return 'text/csv'
elif file_path.lower().endswith('.xlsx'):
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
else:
return 'application/octet-stream'
# Define your email server details
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'vxay jiss cctw lsdo'
st.set_page_config(page_title="Alerter",page_icon="",layout="centered")
html_title = """
<style>
.fixed-title {
font-size: 60px;
color: #ffffff;
background-image: linear-gradient(to right, #ff0000, #ffdab9);
background-clip: text;
-webkit-background-clip: text;
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
text-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}
</style>
<h1 class="fixed-title">Alerter</h1>
"""
st.markdown(html_title, unsafe_allow_html=True)
menu_options = [
{"label": "Internal users", "icon": "π", "description": "Upload a document and schedule it for email"},
{"label": "External users", "icon": "π", "description": "Schedule an email with BigQuery data"},
{"label": "Recon checking", "icon": "π", "description": "Schedule an email with BigQuery data"},
{"label": "Manual BQ upload", "icon": "π", "description": "Schedule an email with BigQuery data"},
{"label": "Invoice splitter", "icon": "π", "description": "Schedule an email with BigQuery data"},
{"label": "Seller sale validation", "icon": "π", "description": "Schedule an email with BigQuery data"}
]
# Create the custom option menu
selected_option = option_menu(
menu_title="Select Integration", # Title of the menu
options=[option["label"] for option in menu_options], # Displayed options
icons=[option["icon"] for option in menu_options], # Icons next to options
menu_icon="cast", # Icon for the entire menu
default_index=0, # Default selected option
orientation="horizontal" # Orientation of the menu (can be vertical or horizontal)
)
if selected_option == "External users":
html_subject = """
<html>
<head>
<style>
.button {
display: inline-block;
padding: 10px 20px;
border-radius: 12px;
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
box-shadow:
0 6px 12px rgba(0, 0, 0, 0.3),
0 8px 16px rgba(0, 0, 0, 0.2),
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
text-align: center;
position: relative;
transform: translateY(4px);
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
cursor: pointer;
user-select: none;
}
.button:hover {
box-shadow:
0 8px 16px rgba(0, 0, 0, 0.3),
0 12px 24px rgba(0, 0, 0, 0.2);
transform: translateY(2px);
}
.button:active {
box-shadow:
0 4px 8px rgba(0, 0, 0, 0.3),
0 6px 12px rgba(0, 0, 0, 0.2);
transform: translateY(0);
}
</style>
</head>
<body>
<div class="button">
<h3 style="
font-size: 20px;
color: #ffffff;
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
background-clip: text;
-webkit-background-clip: text;
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
margin: 0;
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
">Select an option</h3>
</div>
</body>
</html>
"""
st.markdown(html_subject, unsafe_allow_html=True)
upload_option = st.radio("", ["Upload Spreadsheet (CSV or Excel)", "Google Sheets URL"])
if upload_option == "Upload Spreadsheet (CSV or Excel)":
html_subject = """
<html>
<head>
<style>
.button {
display: inline-block;
padding: 10px 20px;
border-radius: 12px;
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
box-shadow:
0 6px 12px rgba(0, 0, 0, 0.3),
0 8px 16px rgba(0, 0, 0, 0.2),
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
text-align: center;
position: relative;
transform: translateY(4px);
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
cursor: pointer;
user-select: none;
}
.button:hover {
box-shadow:
0 8px 16px rgba(0, 0, 0, 0.3),
0 12px 24px rgba(0, 0, 0, 0.2);
transform: translateY(2px);
}
.button:active {
box-shadow:
0 4px 8px rgba(0, 0, 0, 0.3),
0 6px 12px rgba(0, 0, 0, 0.2);
transform: translateY(0);
}
</style>
</head>
<body>
<div class="button">
<h3 style="
font-size: 20px;
color: #ffffff;
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
background-clip: text;
-webkit-background-clip: text;
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
margin: 0;
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
">Upload documents</h3>
</div>
</body>
</html>
"""
st.markdown(html_subject, unsafe_allow_html=True)
uploaded_file = st.file_uploader("", type=["csv", "xlsx"])
if uploaded_file:
# Load the data
if uploaded_file.name.endswith(".csv"):
df = pd.read_csv(uploaded_file)
else:
df = pd.read_excel(uploaded_file)
st.write("")
st.write("")
elif upload_option == "Google Sheets URL":
html_subject = """
<html>
<head>
<style>
.button {
display: inline-block;
padding: 10px 20px;
border-radius: 12px;
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
box-shadow:
0 6px 12px rgba(0, 0, 0, 0.3),
0 8px 16px rgba(0, 0, 0, 0.2),
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
text-align: center;
position: relative;
transform: translateY(4px);
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
cursor: pointer;
user-select: none;
}
.button:hover {
box-shadow:
0 8px 16px rgba(0, 0, 0, 0.3),
0 12px 24px rgba(0, 0, 0, 0.2);
transform: translateY(2px);
}
.button:active {
box-shadow:
0 4px 8px rgba(0, 0, 0, 0.3),
0 6px 12px rgba(0, 0, 0, 0.2);
transform: translateY(0);
}
</style>
</head>
<body>
<div class="button">
<h3 style="
font-size: 20px;
color: #ffffff;
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
background-clip: text;
-webkit-background-clip: text;
text-fill-color: transparent;
-webkit-text-fill-color: transparent;
margin: 0;
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
">Enter Google sheets url</h3>
</div>
</body>
</html>
"""
st.markdown(html_subject, unsafe_allow_html=True)
sheet_url = st.text_input("")
if sheet_url:
try:
# Define the scope
scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/drive']
# Add credentials
creds = ServiceAccountCredentials.from_json_keyfile_name('fynd-db-48954327ef17.json', scope)
client = gspread.authorize(creds)
# Get the sheet data
sheet = client.open_by_url(sheet_url).sheet1
data = sheet.get_all_records()
df = pd.DataFrame(data)
except Exception as e:
st.error(f"Failed to load Google Sheets: {str(e)}")
if 'df' in locals():
# Display the data (excluding the 'status' column)
df = df.drop(columns=['status'], errors='ignore')
st.dataframe(df)
button_styles = """
<style>
div.stButton > button {
color: #ffffff; /* Text color */
font-size: 30px;
background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 15px;
display: inline-block;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */
transition: all 0.3s ease; /* Smooth transition on hover */
}
div.stButton > button:hover {
background-color: #00ff00; /* Hover background color */
color: #ff0000; /* Hover text color */
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */
}
</style>
"""
st.markdown(button_styles, unsafe_allow_html=True)
if st.button("Send Emails"):
# Send emails
for index, row in df.iterrows():
email = row['Email Addresses']
subject = row['Subject']
message = row['Message']
cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
Folder_IDs = row['Folder IDs'].split(',')
# company_name = row['Company_Name']
# company_id = row['Company_ID']
# Create the email
msg = MIMEMultipart()
msg['From'] = EMAIL_HOST_USER
msg['To'] = email
msg['Subject'] = subject
if cc_addresses:
msg['Cc'] = ','.join(cc_addresses)
body = f"""{message}"""
msg.attach(MIMEText(body, 'plain'))
# Read and attach PDFs
for folder_id in Folder_IDs:
pdf_path = folder_id.strip()
if pdf_path.endswith('.pdf'):
pdf_content = read_file(pdf_path)
if pdf_content:
part = MIMEApplication(pdf_content, Name=os.path.basename(pdf_path))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(pdf_path)}"'
msg.attach(part)
# Read and attach CSV files
for folder_id in Folder_IDs:
csv_path = folder_id.strip()
if csv_path.endswith('.csv'):
csv_content = read_file(csv_path)
if csv_content:
part = MIMEApplication(csv_content, Name=os.path.basename(csv_path))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(csv_path)}"'
msg.attach(part)
# Read and attach XLSX files
for folder_id in Folder_IDs:
xlsx_path = folder_id.strip()
if xlsx_path.endswith('.xlsx'):
xlsx_content = read_file(xlsx_path)
if xlsx_content:
part = MIMEApplication(xlsx_content, Name=os.path.basename(xlsx_path))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(xlsx_path)}"'
msg.attach(part)
# Read and attach ZIP files
for folder_id in Folder_IDs:
zip_path = folder_id.strip()
if zip_path.endswith('.zip'):
zip_content = read_file(zip_path)
if zip_content:
part = MIMEApplication(zip_content, Name=os.path.basename(zip_path))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(zip_path)}"'
msg.attach(part)
# Send the email
try:
with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
server.starttls()
server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
server.sendmail(msg['From'], [email] + cc_addresses, msg.as_string())
st.success(f"Email sent to {email}")
except Exception as e:
st.error(f"Failed to send email to {email}: {str(e)}")
elif selected_option == "Internal users":
with open('ap.py') as file:
exec(file.read())
elif selected_option == "Recon checking":
with open('recon.py') as file:
exec(file.read())
elif selected_option == "Manual BQ upload":
with open('bq.py') as file:
exec(file.read())
elif selected_option == "Invoice splitter":
with open('splitter.py') as file:
exec(file.read())
elif selected_option == "Seller sale validation":
with open('seller.py') as file:
exec(file.read())
|