HEHEBOIOG commited on
Commit
4c347a3
·
verified ·
1 Parent(s): aad89d3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import undetected_chromedriver as uc
3
+ from time import perf_counter, sleep
4
+ import threading
5
+ import time
6
+
7
+ def refresh_page(url, refresh_interval, stop_event):
8
+ # Configure undetected Chrome driver
9
+ options = uc.ChromeOptions()
10
+ options.add_argument("--no-sandbox")
11
+ options.add_argument("--disable-dev-shm-usage")
12
+ options.add_argument("--disable-blink-features=AutomationControlled")
13
+ options.add_argument("--start-maximized")
14
+
15
+ # Initialize the browser
16
+ driver = uc.Chrome(options=options)
17
+
18
+ try:
19
+ # Open the link
20
+ driver.get(url)
21
+ st.write("Loaded the page successfully.")
22
+
23
+ # Refresh loop
24
+ while not stop_event.is_set():
25
+ start_time = perf_counter()
26
+ driver.refresh()
27
+ elapsed_time = perf_counter() - start_time
28
+ st.write(f"Page refreshed. Time taken: {elapsed_time:.6f} seconds")
29
+ time.sleep(refresh_interval)
30
+ except Exception as e:
31
+ st.error(f"An error occurred: {e}")
32
+ finally:
33
+ driver.quit()
34
+
35
+ def main():
36
+ st.title("Web Page Auto-Refresh")
37
+
38
+ # URL input
39
+ url = st.text_input("Enter URL to refresh",
40
+ "https://solscan.io/account/FWH9cXncf2C7fmbRhweeNGLNKKZ23qiyXyBk4ex8ic3y")
41
+
42
+ # Refresh interval input
43
+ refresh_interval = st.slider("Refresh Interval (seconds)",
44
+ min_value=0.5,
45
+ max_value=10.0,
46
+ value=4.0,
47
+ step=0.5)
48
+
49
+ # Stop event for thread control
50
+ stop_event = threading.Event()
51
+
52
+ # Start and Stop buttons
53
+ col1, col2 = st.columns(2)
54
+
55
+ with col1:
56
+ if st.button("Start Refreshing"):
57
+ # Create and start the thread
58
+ refresh_thread = threading.Thread(
59
+ target=refresh_page,
60
+ args=(url, refresh_interval, stop_event)
61
+ )
62
+ refresh_thread.start()
63
+ st.session_state.refresh_thread = refresh_thread
64
+ st.success("Refreshing started!")
65
+
66
+ with col2:
67
+ if st.button("Stop Refreshing"):
68
+ if hasattr(st.session_state, 'refresh_thread'):
69
+ stop_event.set()
70
+ st.session_state.refresh_thread.join()
71
+ st.warning("Refreshing stopped!")
72
+
73
+ if __name__ == "__main__":
74
+ main()