Created
September 8, 2021 11:06
-
-
Save melvinpetix/3d647f6b7605ab6b88e15fa7f49ec5ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.policy import default | |
import os | |
import schedule | |
import time | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.mime.image import MIMEImage | |
from dashboard_exporter import exporter | |
import mimetypes | |
import time | |
from selenium import webdriver | |
from selenium.webdriver import ChromeOptions | |
from selenium.webdriver.common.action_chains import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
options = ChromeOptions() | |
options.add_argument("--disable-gpu") | |
options.add_argument("--no-sandbox") | |
options.add_argument("--start-maximized") | |
options.add_argument("--disable-dev-shm-usage") | |
options.add_argument("--headless") | |
#driver = webdriver.Chrome(options=options) | |
driver = webdriver.Chrome(options=options) | |
URL = 'https://prod1-airflow.usapcld.io/login/?next=https%3A%2F%2Fprod1-airflow.usapcld.io%2Fhome' | |
driver.get(URL) | |
time.sleep(20) | |
driver.maximize_window() | |
driver.find_element_by_id('username').send_keys("USERNAME") | |
driver.find_element_by_id('password').send_keys("PASSWORD") | |
action = ActionChains(driver) | |
action.send_keys(Keys.ENTER) | |
action.perform() | |
driver.set_window_size(1920,1080) | |
driver.find_element_by_tag_name('body').screenshot('dags2.png') | |
time.sleep(30) | |
driver.maximize_window() | |
URL = 'https://ds-dashboard.usapcld.io/executive' | |
driver.get(URL) | |
time.sleep(30) | |
driver.set_window_size(1920,1080) | |
driver.find_element_by_tag_name('body').screenshot('dags1.png') | |
driver.quit() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTk0MDc1NA' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTk0MDc1NA", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('error1') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTcyOTkzMw' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTcyOTkzMw", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('error2') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTcyOTkzNg' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTcyOTkzNg", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('error3') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0NA' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0NA", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('dashboard1') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0OA' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0OA", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('dashboard2') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
os.environ['API_KEY'] = 'NRAK-FQH677810Q2JU2RA3CVJCNQSWHK' | |
os.environ['GUID'] = 'MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0Nw' | |
output = exporter( | |
personal_api_key= "NRAK-FQH677810Q2JU2RA3CVJCNQSWHK", | |
guid= "MjAxODkwfFZJWnxEQVNIQk9BUkR8MTg0NDU0Nw", | |
file_type="PNG", | |
) | |
content_type = output.headers["content-type"] | |
extension = mimetypes.guess_extension(content_type) | |
output_directory = '.' | |
filename = ('dashboard3') | |
of = "%s/%s%s" % (output_directory, filename, extension) | |
with open(of, "wb") as f: | |
f.write(output.content) | |
f.close() | |
time.sleep(5) | |
strFrom = 'noreply@usautoparts.com' | |
strTo = 'WebOps - GRP Technology <b0d411e0.usautoparts.com@amer.teams.ms>' | |
# Create the root message and fill in the from, to, and subject headers | |
msgRoot = MIMEMultipart('related') | |
msgRoot['Subject'] = '' | |
msgRoot['From'] = strFrom | |
msgRoot['To'] = strTo | |
msgRoot.preamble = 'This is a multi-part message in MIME format.' | |
# Encapsulate the plain and HTML versions of the message body in an | |
# 'alternative' part, so message agents can decide which they want to display. | |
msgAlternative = MIMEMultipart('alternative') | |
msgRoot.attach(msgAlternative) | |
msgText = MIMEText('This is plain.') | |
msgAlternative.attach(msgText) | |
# We reference the image in the IMG SRC attribute by the ID we give it below | |
msgText = MIMEText('Response Time<br><img src="cid:image1" width="1820" height="900"><img src="cid:image2" width="1820" height="900"><img src="cid:image3" width="1820" height="900">', 'html') | |
msgAlternative.attach(msgText) | |
# Image location | |
fp = open('dashboard1.png', 'rb') | |
msgImage1 = MIMEImage(fp.read()) | |
fp.close() | |
fp = open('dashboard2.png', 'rb') | |
msgImage2 = MIMEImage(fp.read()) | |
fp.close() | |
fp = open('dashboard3.png', 'rb') | |
msgImage3 = MIMEImage(fp.read()) | |
fp.close() | |
# msgImage definition and attachment | |
msgImage1.add_header('Content-ID', '<image1>') | |
msgImage2.add_header('Content-ID', '<image2>') | |
msgImage3.add_header('Content-ID', '<image3>') | |
msgRoot.attach(msgImage1) | |
msgRoot.attach(msgImage2) | |
msgRoot.attach(msgImage3) | |
# Send the email (this example assumes SMTP authentication is required) | |
import smtplib | |
smtp = smtplib.SMTP('mail.usautoparts.com', '25') | |
smtp.starttls() | |
smtp.sendmail('noreply@usautoparts.com', strTo, msgRoot.as_string()) | |
smtp.quit() | |
strFrom = 'noreply@usautoparts.com' | |
strTo = 'WebOps - GRP Technology <b0d411e0.usautoparts.com@amer.teams.ms>' | |
# Create the root message and fill in the from, to, and subject headers | |
msgRoot = MIMEMultipart('related') | |
msgRoot['Subject'] = '' | |
msgRoot['From'] = strFrom | |
msgRoot['To'] = strTo | |
msgRoot.preamble = 'This is a multi-part message in MIME format.' | |
# Encapsulate the plain and HTML versions of the message body in an | |
# 'alternative' part, so message agents can decide which they want to display. | |
msgAlternative = MIMEMultipart('alternative') | |
msgRoot.attach(msgAlternative) | |
msgText = MIMEText('This is plain.') | |
msgAlternative.attach(msgText) | |
# We reference the image in the IMG SRC attribute by the ID we give it below | |
msgText = MIMEText('DAGS and Dashboard<br><img src="cid:image1" width="1820" height="1080"><img src="cid:image2" width="1820" height="1080">', 'html') | |
msgAlternative.attach(msgText) | |
# Image location | |
fp = open('dags1.png', 'rb') | |
msgImage1 = MIMEImage(fp.read()) | |
fp.close() | |
fp = open('dags2.png', 'rb') | |
msgImage2 = MIMEImage(fp.read()) | |
fp.close() | |
# msgImage definition and attachment | |
msgImage1.add_header('Content-ID', '<image1>') | |
msgImage2.add_header('Content-ID', '<image2>') | |
msgRoot.attach(msgImage1) | |
msgRoot.attach(msgImage2) | |
# Send the email (this example assumes SMTP authentication is required) | |
import smtplib | |
smtp = smtplib.SMTP('mail.usautoparts.com', '25') | |
smtp.starttls() | |
smtp.sendmail('noreply@usautoparts.com', strTo, msgRoot.as_string()) | |
smtp.quit() | |
time.sleep(15) | |
strFrom = 'noreply@usautoparts.com' | |
strTo = 'WebOps - GRP Technology <b0d411e0.usautoparts.com@amer.teams.ms>' | |
# Create the root message and fill in the from, to, and subject headers | |
msgRoot = MIMEMultipart('related') | |
msgRoot['Subject'] = '' | |
msgRoot['From'] = strFrom | |
msgRoot['To'] = strTo | |
msgRoot.preamble = 'This is a multi-part message in MIME format.' | |
# Encapsulate the plain and HTML versions of the message body in an | |
# 'alternative' part, so message agents can decide which they want to display. | |
msgAlternative = MIMEMultipart('alternative') | |
msgRoot.attach(msgAlternative) | |
msgText = MIMEText('This is plain.') | |
msgAlternative.attach(msgText) | |
# We reference the image in the IMG SRC attribute by the ID we give it below | |
msgText = MIMEText('Alerting Entities<img src="cid:image1" width="1820" height="900"><img src="cid:image2" width="1820" height="900"><img src="cid:image3" width="1820" height="900">', 'html') | |
msgAlternative.attach(msgText) | |
# This example assumes the image is in the current directory | |
fp = open('error1.png', 'rb') | |
msgImage1 = MIMEImage(fp.read()) | |
fp.close() | |
fp = open('error2.png', 'rb') | |
msgImage2 = MIMEImage(fp.read()) | |
fp.close() | |
fp = open('error3.png', 'rb') | |
msgImage3 = MIMEImage(fp.read()) | |
fp.close() | |
# Define the image's ID as referenced above | |
msgImage1.add_header('Content-ID', '<image1>') | |
msgImage2.add_header('Content-ID', '<image2>') | |
msgImage3.add_header('Content-ID', '<image3>') | |
msgRoot.attach(msgImage1) | |
msgRoot.attach(msgImage2) | |
msgRoot.attach(msgImage3) | |
# Send the email (this example assumes SMTP authentication is required) | |
import smtplib | |
smtp = smtplib.SMTP('mail.usautoparts.com', '25') | |
smtp.starttls() | |
smtp.sendmail('noreply@usautoparts.com', strTo, msgRoot.as_string()) | |
smtp.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment