ayush-thakur02 commited on
Commit
eacc5d3
1 Parent(s): a87e510

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -43
app.py CHANGED
@@ -1,50 +1,29 @@
1
- import gradio as gr
2
- import subprocess
3
- import threading
4
  import time
5
 
6
- # Define the URL and interval
7
- url = 'https://baseline-btn5.onrender.com/'
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
- # Variables for subprocess and count
12
- count = 0
13
- subprocess_process = None
14
 
15
- def open_website():
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
- open_website()
38
- time.sleep(interval) # Wait for the specified interval before opening the website again
39
-
40
- # Start the background thread to manage website opening and subprocess termination
41
- threading.Thread(target=background_task, daemon=True).start()
42
-
43
- # Define the Gradio interface
44
- def interface_function():
45
- return f"Website opened count: {get_count()}"
46
-
47
- iface = gr.Interface(fn=interface_function, inputs=[], outputs="text")
 
 
 
 
48
 
49
  if __name__ == "__main__":
50
- iface.launch(debug=True)
 
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)