Skip to content

Instantly share code, notes, and snippets.

@spenkk
Last active January 20, 2020 22:52
Show Gist options
  • Save spenkk/5909ed2d5bfb8782751eaae6d8176c1d to your computer and use it in GitHub Desktop.
Save spenkk/5909ed2d5bfb8782751eaae6d8176c1d to your computer and use it in GitHub Desktop.
Website Monitor with Discord Notifications
import os
import sys
import requests
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.common.exceptions import TimeoutException
options = FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.set_page_load_timeout(5)
url = ""
discord_webhook = "https://discordapp.com/api/webhooks/<...>"
screenshot_path = "/root/images/screenshot.png"
r = requests.get(url)
if r.status_code != 200:
from discord_webhook import DiscordWebhook, DiscordEmbed
webhook = DiscordWebhook(url=discord_webhook)
driver.get(r.url)
driver.save_screenshot(screenshot_path)
print("[*] Screenshot taken on {}".format(url))
with open(screenshot_path, "rb") as f:
webhook.add_file(file=f.read(), filename=screenshot_path)
embed = DiscordEmbed(title='Website is having some problems', description='<@USER-ID> Please have a look\nStatus code: {}'.format(r.status_code), color=242424)
webhook.add_embed(embed)
response = webhook.execute()
print("[*] Screenshot sent on discord")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment