Website Stats App

 
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")

About this template

The Website Stats App is a bot that provides detailed statistics about a given website. It visits the website, determines its load time, status, and security level. The app also handles errors for incorrect URLs, notifies the user if the website processing is taking some time, and alerts the user if the website is down or not reachable. Additionally, the app automatically posts updates on a Discord channel every 7 hours. If Discord credentials and channel ID for Discord are present, it will use that. The environment variables required for this app are: DISCORD_WEBHOOK_URL, and WEBSITE_URL.

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.

Category
Technology
Last published
June 15, 2024

More templates like this

PDF Data Extraction and Excel Transfer

An app for extracting name, phone number, and email data from PDF files and transferring it to Excel.

PDF
Python

Discord Ticketbot Template

A simple Discord Ticketbot for your Discord Support Department. This Template and Bot is fully customizable but already build so that you can use it right away. You need a bot token from https://discord.com/developers/applications for your bot to work. These are the steps needed to get your token: "1. 🌐 Go to the Discord Developer Portal. 🌐\n" + "2. 🆕 Create a new application and navigate to the 'Bot' section. 🤖\n" + "3. 📋 Under the 'TOKEN' section, click 'Reset Token' to get your Discord bot token and confirm by clicking 'Yes, do it'. 🔑\n" + "4. 🤖 If your bot will have any ability to read/reply to messages, then under the 'BOT' section, enable the slider titled 'Message Content Intent' ✅" + "5. 🔐 Set the 'DISCORD_BOT_TOKEN' in the Env Secrets tab with your bot token from step 3. 🔐\n" + "For bot permissions, it's recommended to start with basic permissions and adjust as needed for your app's functionality.🚀") If you encounter any bugs, please tell Lazy to fix them and report them on the Official Lazy AI Discord to @D4vidG4merLP. Credits: @meow - the Discord bot slash command template @mrlazy.notlazy - supporting me And the Biggest Thank you. You for using this template ❤️

Discord

GPT-4 Exam Generator

This app uses GPT-4 to generate a PDF of a new exam based on an uploaded PDF of a past exam.

PDF
OpenAI
Python
Home
/
Website Stats App