File size: 2,388 Bytes
4c347a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import streamlit as st
import undetected_chromedriver as uc
from time import perf_counter, sleep
import threading
import time

def refresh_page(url, refresh_interval, stop_event):
    # Configure undetected Chrome driver
    options = uc.ChromeOptions()
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--disable-blink-features=AutomationControlled")
    options.add_argument("--start-maximized")

    # Initialize the browser
    driver = uc.Chrome(options=options)

    try:
        # Open the link
        driver.get(url)
        st.write("Loaded the page successfully.")

        # Refresh loop
        while not stop_event.is_set():
            start_time = perf_counter()
            driver.refresh()
            elapsed_time = perf_counter() - start_time
            st.write(f"Page refreshed. Time taken: {elapsed_time:.6f} seconds")
            time.sleep(refresh_interval)
    except Exception as e:
        st.error(f"An error occurred: {e}")
    finally:
        driver.quit()

def main():
    st.title("Web Page Auto-Refresh")

    # URL input
    url = st.text_input("Enter URL to refresh", 
                        "https://solscan.io/account/FWH9cXncf2C7fmbRhweeNGLNKKZ23qiyXyBk4ex8ic3y")
    
    # Refresh interval input
    refresh_interval = st.slider("Refresh Interval (seconds)", 
                                 min_value=0.5, 
                                 max_value=10.0, 
                                 value=4.0, 
                                 step=0.5)

    # Stop event for thread control
    stop_event = threading.Event()

    # Start and Stop buttons
    col1, col2 = st.columns(2)
    
    with col1:
        if st.button("Start Refreshing"):
            # Create and start the thread
            refresh_thread = threading.Thread(
                target=refresh_page, 
                args=(url, refresh_interval, stop_event)
            )
            refresh_thread.start()
            st.session_state.refresh_thread = refresh_thread
            st.success("Refreshing started!")

    with col2:
        if st.button("Stop Refreshing"):
            if hasattr(st.session_state, 'refresh_thread'):
                stop_event.set()
                st.session_state.refresh_thread.join()
                st.warning("Refreshing stopped!")

if __name__ == "__main__":
    main()