Website Stats App

Start with this template
508
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import requests
import os
import asyncio
from discord_webhook import DiscordWebhook

# Obtain the Discord webhook URL from environment variables
discord_webhook_url = os.environ.get('DISCORD_WEBHOOK_URL', None)

# Obtain the website URL from environment variables
website_link = os.environ.get('WEBSITE_URL', None)

def website_stats():
    # Check if the URL is correct
    if not website_link.startswith("http://") and not website_link.startswith("https://"):
        print("The URL is not correct. Please enter a valid URL.")
        return

    options = Options()
    options.add_argument("--no-sandbox")
    options.add_argument("--headless")
Get full code

Website Stats App

Created: | Last Updated:

Introduction to the Website Stats App Template

Welcome to the Website Stats App template! This template is designed to help you monitor the performance of a website by checking its load time, status, and security level. It also includes functionality to automatically post these statistics to a Discord channel every 7 hours. This is an excellent tool for website administrators and developers who want to keep an eye on their site's performance and ensure it remains accessible to users.

Clicking Start with this Template

To begin using this template, simply click on the "Start with this Template" button. This will set up the template in your Lazy builder interface, pre-populating the code so you can customize it according to your needs without any additional code copying or pasting.

Initial Setup

Before you can use this app, you'll need to set up a couple of environment secrets within the Lazy Builder. These are:

  • DISCORD_WEBHOOK_URL: The URL of the Discord webhook where you want to post the website statistics.
  • WEBSITE_URL: The URL of the website you want to monitor.

To obtain the Discord webhook URL, you'll need to create a webhook in your Discord server. Here's how:

  1. Go to your Discord server settings and select the 'Integrations' tab.
  2. Click on 'Create Webhook' and set up the name and channel where you want the messages to be posted.
  3. Copy the 'WEBHOOK URL' provided by Discord.

Once you have your Discord webhook URL and the website URL you want to monitor, enter them into the Environment Secrets tab within the Lazy Builder.

Test: Pressing the Test Button

After setting up your environment secrets, press the "Test" button to begin the deployment of the app. The Lazy CLI will handle the deployment process, and you won't need to install any libraries or set up your environment.

Using the App

Once the app is deployed, it will automatically start monitoring the website based on the URL you provided. It will check the website's load time, status, and security level, and then post this information to the specified Discord channel every 7 hours. You don't need to interact with the app directly; it runs in the background and sends updates automatically.

Integrating the App

If you want to integrate the statistics posted by this app into another tool or service, you can use the Discord webhook URL to receive the messages. You can also modify the template code to send the data to other services if needed. For example, if you want to send the data to a different endpoint, you can modify the webhook execution part of the code:

# Replace the following line with your custom integration code response = webhook.execute() Remember to replace the placeholder code with the actual code required to integrate with your chosen service.

By following these steps, you can easily set up and use the Website Stats App template on the Lazy platform to monitor your website's performance and keep your team updated through Discord.

Technologies

Discord Discord
Python Python