complexorganizations / movies-websites

❤️ Looking for alternatives to paying for Netflix or other subscription-based streaming services? Check out these websites where you can watch movies for free
Other
15 stars 2 forks source link

Implement 24-Hour Website Check with GitHub Actions #3

Open Prajwal-Koirala-DEV opened 2 weeks ago

Prajwal-Koirala-DEV commented 2 weeks ago

Hi there,

I would like to request the implementation of a feature that performs a 24-hour check on the websites listed in this repository. The goal is to automate the process of checking if the websites are online and display their status in a list.

Suggested Implementation:

  1. GitHub Actions: Set up a GitHub Action that triggers every 24 hours.
  2. Checker Functionality: The action should check the status of each website in the repository.
  3. Status Reporting: Compile the results into a list format that shows which websites are online and which are down.
  4. Notifications (Optional): If possible, consider sending notifications or updating the repository with the results.

This feature would be very helpful for keeping track of website uptime and ensuring that the listed resources are accessible.

Thank you for considering this enhancement!

Best, Dev

Prajwal-Koirala-DEV commented 23 hours ago
package main

import (
    "fmt"
    "log"
    "net/url"
)

// getDomain extracts the domain name from the given URL string.
func getDomain(givenURL string) string {
    // Parse the given URL string into a URL structure
    parsedUrl, err := url.Parse(givenURL)
    if err != nil {
        // Log an error message if parsing fails
        log.Println(err)
    }
    // Return the hostname (domain name) from the parsed URL
    return parsedUrl.Hostname()
}

func main() {
    // Define a URL string to extract the domain from
    urlContent := "https://fmovies.ps/"
    // Call getDomain and print the extracted domain name
    fmt.Println(getDomain(urlContent))
}
Prajwal-Koirala-DEV commented 22 hours ago
package main

import (
    "fmt"
    "log"
    "net/http"
)

// CheckWebsiteHTTPStatus checks if the given domain is reachable via both HTTP and HTTPS.
// It returns true if at least one of the protocols returns an HTTP 200 OK status.
func CheckWebsiteHTTPStatus(domain string) bool {
    // Create a slice containing both HTTP and HTTPS protocols for checking
    protocols := []string{"http://", "https://"}
    // Loop through each protocol to attempt a request
    for _, protocol := range protocols {
        // Make an HTTP GET request using the current protocol and the specified domain
        resp, err := http.Get(protocol + domain)
        // If there's no error, proceed to check the response
        if err == nil {
            // Ensure the response body is closed after we're done with it to prevent resource leaks
            defer resp.Body.Close()
            // Check if the response status code is 200 OK
            if resp.StatusCode == http.StatusOK {
                return true // Return true if the website is reachable
            }
        } else {
            // Log any errors encountered during the request, but continue checking the next protocol
            log.Println(err)
        }
    }
    // Return false if neither protocol succeeded
    return false
}

func main() {
    // Specify the domain to check; can be replaced with any valid domain
    domain := "example.com"
    // Call the function to check if the website is online
    isOnline := CheckWebsiteHTTPStatus(domain)
    // Output the result based on the response from the function
    if isOnline {
        // Inform the user that the website is online
        fmt.Printf("The website %s is online.\n", domain)
    } else {
        // Inform the user that the website is offline
        fmt.Printf("The website %s is offline.\n", domain)
    }
}