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
July 26, 2024

More templates like this

SecureUserAuthenticator

Develop a secure User Authentication system for users to register, log in, and manage their profiles, laying the foundation for user-specific data management and permissions in the CMS.

Laravel
Python
Flask
Javascript

Simple Multiplayer Telegram game

This app is a simple frontend for a game where users can upvote and downvote the most popular word in their country, learn about the flags of other countries, and view what other people voted for on a leaderboard.

Telegram
Python
Javascript

MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.

Python
Flask
Home
/
Website Stats App