File size: 1,602 Bytes
eacc5d3
e8f127f
3f93d5d
 
e8f127f
eacc5d3
 
e8f127f
3f93d5d
 
e8f127f
3f93d5d
 
 
 
 
e8f127f
eacc5d3
 
 
 
 
 
3f93d5d
 
eacc5d3
 
 
 
 
 
 
 
e8f127f
3f93d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8f127f
3f93d5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
import time
import threading
import gradio as gr

# Define the URL of the website you want to keep active
url = "https://baseline-btn5.onrender.com/"

# Define the interval in seconds (5 minutes to ensure it's active before 6 minutes)
interval = 5 * 60

# Variable to keep track of request counts
request_count = 0

def keep_site_active():
    global request_count
    while True:
        try:
            # Send a GET request to the website
            response = requests.get(url)
            
            # Check if the request was successful (status code 200)
            if response.status_code == 200:
                # print(f"Successfully accessed {url} - Status Code: {response.status_code}")
                request_count += 1
            else:
                print(f"Failed to access {url} - Status Code: {response.status_code}")

        except requests.RequestException as e:
            print(f"An error occurred: {e}")

        # Wait for the specified interval before making the next request
        time.sleep(interval)

def get_request_count():
    return request_count

def main():
    # Start the site-keeping thread
    threading.Thread(target=keep_site_active, daemon=True).start()
    
    # Define the Gradio interface
    with gr.Blocks() as demo:
        gr.Markdown("# Website Request Tracker")
        count_button = gr.Button("Get Request Count")
        count_display = gr.Textbox(label="Number of Successful Requests")

        count_button.click(fn=get_request_count, outputs=count_display)
    
    demo.launch()

if __name__ == "__main__":
    main()