Spaces:
Sleeping
Sleeping
File size: 1,587 Bytes
e8f127f |
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 |
import gradio as gr
import subprocess
import threading
import time
# Define the URL and interval
url = 'https://baseline-btn5.onrender.com/'
interval = 13 * 60 # 13 minutes in seconds
subprocess_duration = 60 # Duration to run the subprocess in seconds (e.g., 60 seconds)
# Variables for subprocess and count
count = 0
subprocess_process = None
def open_website():
global subprocess_process, count
count += 1
if subprocess_process:
subprocess_process.terminate() # Terminate the previous subprocess if it exists
# Start a new subprocess to open the website
subprocess_process = subprocess.Popen(["python", "-c", f"import webbrowser; webbrowser.open('{url}')"])
# print(f"Website {url} opened. Count: {count}")
# Wait for the subprocess duration and then terminate it
time.sleep(subprocess_duration)
if subprocess_process:
subprocess_process.terminate() # Ensure subprocess is terminated after its run time
subprocess_process = None
def get_count():
return count
def background_task():
while True:
open_website()
time.sleep(interval) # Wait for the specified interval before opening the website again
# Start the background thread to manage website opening and subprocess termination
threading.Thread(target=background_task, daemon=True).start()
# Define the Gradio interface
def interface_function():
return f"Website opened count: {get_count()}"
iface = gr.Interface(fn=interface_function, inputs=[], outputs="text")
if __name__ == "__main__":
iface.launch(debug=True)
|