Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,29 @@
|
|
1 |
-
import
|
2 |
-
import subprocess
|
3 |
-
import threading
|
4 |
import time
|
5 |
|
6 |
-
# Define the URL
|
7 |
-
url =
|
8 |
-
interval = 13 * 60 # 13 minutes in seconds
|
9 |
-
subprocess_duration = 60 # Duration to run the subprocess in seconds (e.g., 60 seconds)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
subprocess_process = None
|
14 |
|
15 |
-
def
|
16 |
-
global subprocess_process, count
|
17 |
-
count += 1
|
18 |
-
|
19 |
-
if subprocess_process:
|
20 |
-
subprocess_process.terminate() # Terminate the previous subprocess if it exists
|
21 |
-
|
22 |
-
# Start a new subprocess to open the website
|
23 |
-
subprocess_process = subprocess.Popen(["python", "-c", f"import webbrowser; webbrowser.open('{url}')"])
|
24 |
-
# print(f"Website {url} opened. Count: {count}")
|
25 |
-
|
26 |
-
# Wait for the subprocess duration and then terminate it
|
27 |
-
time.sleep(subprocess_duration)
|
28 |
-
if subprocess_process:
|
29 |
-
subprocess_process.terminate() # Ensure subprocess is terminated after its run time
|
30 |
-
subprocess_process = None
|
31 |
-
|
32 |
-
def get_count():
|
33 |
-
return count
|
34 |
-
|
35 |
-
def background_task():
|
36 |
while True:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
-
|
|
|
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 (13 minutes to ensure it's active before 14 minutes)
|
8 |
+
interval = 13 * 60
|
|
|
9 |
|
10 |
+
def keep_site_active(url, interval):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
while True:
|
12 |
+
try:
|
13 |
+
# Send a GET request to the website
|
14 |
+
response = requests.get(url)
|
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 |
+
|
22 |
+
except requests.RequestException as e:
|
23 |
+
print(f"An error occurred: {e}")
|
24 |
+
|
25 |
+
# Wait for the specified interval before making the next request
|
26 |
+
time.sleep(interval)
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
+
keep_site_active(url, interval)
|