IJ-Reynolds HF Staff commited on
Commit
b9d70d9
·
verified ·
1 Parent(s): 296e635

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +29 -10
streamlit_app.py CHANGED
@@ -62,17 +62,18 @@ def start_background_scheduler():
62
  while True:
63
  try:
64
  needs_run = True
65
- sleep_time = 12 * 3600
66
  with data_lock:
67
  if CSV_PATH.exists():
68
  df_check = pd.read_csv(CSV_PATH)
69
  if 'date_collected' in df_check.columns and not df_check.empty:
70
  last_date = pd.to_datetime(df_check['date_collected']).max()
71
  if last_date.tzinfo is not None: last_date = last_date.tz_localize(None)
 
72
  hours_since_last = (datetime.now() - last_date).total_seconds() / 3600
73
- if hours_since_last < 12:
74
  needs_run = False
75
- sleep_time = (12 - hours_since_last) * 3600
76
  if needs_run:
77
  with data_lock: main.run()
78
  time.sleep(sleep_time)
@@ -142,18 +143,36 @@ with st.sidebar:
142
  last_sync_str = "Pending First Run"
143
  if df is not None and not df.empty and 'date_collected' in df.columns:
144
  last_sync_dt = pd.to_datetime(df['date_collected']).max()
145
- # UTC indicator maintained for accurate server time context
146
  last_sync_str = last_sync_dt.strftime('%b %d, %I:%M %p UTC')
147
- st.info(f"**Auto-Pilot:** Active (12h Cycle)\n\n**Last Sync:** {last_sync_str}")
148
 
149
  st.divider()
150
  st.header("Manual Override")
151
- if st.button("Force Manual Sweep", use_container_width=True):
152
- with st.spinner("Scanning Master Schedules and Media..."):
153
- with data_lock: main.run()
154
- st.success("Sweep Complete!")
155
- st.rerun()
 
 
 
 
 
 
 
 
 
156
 
 
 
 
 
 
 
 
 
 
 
157
  st.divider()
158
  if active_df is not None and not active_df.empty:
159
  available_types = active_df['type'].dropna().unique().tolist()
 
62
  while True:
63
  try:
64
  needs_run = True
65
+ sleep_time = 1 * 3600 # 1 Hour
66
  with data_lock:
67
  if CSV_PATH.exists():
68
  df_check = pd.read_csv(CSV_PATH)
69
  if 'date_collected' in df_check.columns and not df_check.empty:
70
  last_date = pd.to_datetime(df_check['date_collected']).max()
71
  if last_date.tzinfo is not None: last_date = last_date.tz_localize(None)
72
+
73
  hours_since_last = (datetime.now() - last_date).total_seconds() / 3600
74
+ if hours_since_last < 1:
75
  needs_run = False
76
+ sleep_time = (1 - hours_since_last) * 3600
77
  if needs_run:
78
  with data_lock: main.run()
79
  time.sleep(sleep_time)
 
143
  last_sync_str = "Pending First Run"
144
  if df is not None and not df.empty and 'date_collected' in df.columns:
145
  last_sync_dt = pd.to_datetime(df['date_collected']).max()
 
146
  last_sync_str = last_sync_dt.strftime('%b %d, %I:%M %p UTC')
147
+ st.info(f"**Auto-Pilot:** Active (1h Cycle)\n\n**Last Sync:** {last_sync_str}")
148
 
149
  st.divider()
150
  st.header("Manual Override")
151
+
152
+ # --- THE ANTI-SPAM COOLDOWN ---
153
+ cooldown_minutes = 15
154
+ can_sweep = True
155
+ time_left = 0
156
+
157
+ if df is not None and not df.empty and 'date_collected' in df.columns:
158
+ last_sync_dt = pd.to_datetime(df['date_collected']).max()
159
+ if last_sync_dt.tzinfo is not None: last_sync_dt = last_sync_dt.tz_localize(None)
160
+ mins_since_last = (datetime.now() - last_sync_dt).total_seconds() / 60
161
+
162
+ if mins_since_last < cooldown_minutes:
163
+ can_sweep = False
164
+ time_left = int(cooldown_minutes - mins_since_last)
165
 
166
+ if can_sweep:
167
+ if st.button("Force Manual Sweep", use_container_width=True):
168
+ with st.spinner("Scanning Datacenters & Gov Servers..."):
169
+ with data_lock: main.run()
170
+ st.success("Sweep Complete!")
171
+ st.rerun()
172
+ else:
173
+ st.button(f"Sweep on Cooldown ({time_left}m left)", disabled=True, use_container_width=True)
174
+ st.caption("🛡️ *To prevent IP bans from government servers, manual sweeps are limited to once every 15 minutes.*")
175
+
176
  st.divider()
177
  if active_df is not None and not active_df.empty:
178
  available_types = active_df['type'].dropna().unique().tolist()