Spaces:
Sleeping
Sleeping
ayush-thakur02
commited on
Commit
•
3f93d5d
1
Parent(s):
eacc5d3
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,19 @@
|
|
1 |
import requests
|
2 |
import time
|
|
|
|
|
3 |
|
4 |
# Define the URL of the website you want to keep active
|
5 |
url = "https://baseline-btn5.onrender.com/"
|
6 |
|
7 |
-
# Define the interval in seconds (
|
8 |
-
interval =
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
while True:
|
12 |
try:
|
13 |
# Send a GET request to the website
|
@@ -15,7 +21,8 @@ def keep_site_active(url, interval):
|
|
15 |
|
16 |
# Check if the request was successful (status code 200)
|
17 |
if response.status_code == 200:
|
18 |
-
print(f"Successfully accessed {url} - Status Code: {response.status_code}")
|
|
|
19 |
else:
|
20 |
print(f"Failed to access {url} - Status Code: {response.status_code}")
|
21 |
|
@@ -25,5 +32,22 @@ def keep_site_active(url, interval):
|
|
25 |
# Wait for the specified interval before making the next request
|
26 |
time.sleep(interval)
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
if __name__ == "__main__":
|
29 |
-
|
|
|
1 |
import requests
|
2 |
import time
|
3 |
+
import threading
|
4 |
+
import gradio as gr
|
5 |
|
6 |
# Define the URL of the website you want to keep active
|
7 |
url = "https://baseline-btn5.onrender.com/"
|
8 |
|
9 |
+
# Define the interval in seconds (5 minutes to ensure it's active before 6 minutes)
|
10 |
+
interval = 5 * 60
|
11 |
|
12 |
+
# Variable to keep track of request counts
|
13 |
+
request_count = 0
|
14 |
+
|
15 |
+
def keep_site_active():
|
16 |
+
global request_count
|
17 |
while True:
|
18 |
try:
|
19 |
# Send a GET request to the website
|
|
|
21 |
|
22 |
# Check if the request was successful (status code 200)
|
23 |
if response.status_code == 200:
|
24 |
+
# print(f"Successfully accessed {url} - Status Code: {response.status_code}")
|
25 |
+
request_count += 1
|
26 |
else:
|
27 |
print(f"Failed to access {url} - Status Code: {response.status_code}")
|
28 |
|
|
|
32 |
# Wait for the specified interval before making the next request
|
33 |
time.sleep(interval)
|
34 |
|
35 |
+
def get_request_count():
|
36 |
+
return request_count
|
37 |
+
|
38 |
+
def main():
|
39 |
+
# Start the site-keeping thread
|
40 |
+
threading.Thread(target=keep_site_active, daemon=True).start()
|
41 |
+
|
42 |
+
# Define the Gradio interface
|
43 |
+
with gr.Blocks() as demo:
|
44 |
+
gr.Markdown("# Website Request Tracker")
|
45 |
+
count_button = gr.Button("Get Request Count")
|
46 |
+
count_display = gr.Textbox(label="Number of Successful Requests")
|
47 |
+
|
48 |
+
count_button.click(fn=get_request_count, outputs=count_display)
|
49 |
+
|
50 |
+
demo.launch()
|
51 |
+
|
52 |
if __name__ == "__main__":
|
53 |
+
main()
|