soxogvv commited on
Commit
bd896c1
Β·
verified Β·
1 Parent(s): 522c46a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -85,39 +85,37 @@ def apply_today_plan():
85
  )
86
  def reset_and_plan():
87
  tz = pytz.timezone("Asia/Kolkata")
88
- now = datetime.now(tz).replace(second=0, microsecond=0)
89
- end_of_day = now.replace(hour=23, minute=59)
90
-
91
- plans.delete_many({}) # Remove old plans
92
 
93
  for acc in accounts.find():
94
  limit = random.randint(3, 5)
95
  times = set()
96
  attempts = 0
97
 
98
- while len(times) < limit and attempts < 50:
 
99
  attempts += 1
 
100
  minutes_left = int((end_of_day - now).total_seconds() // 60)
101
- if minutes_left <= 5:
102
- logging.info("⏹️ Not enough time left today!")
103
- break
104
 
105
- random_minutes = random.randint(1, minutes_left)
106
  future_time = now + timedelta(minutes=random_minutes)
107
 
108
- # βœ… Only accept times strictly greater than 'now'
109
- if future_time > now:
110
- times.add(future_time)
111
 
112
- schedule_times = sorted(times)
113
- if schedule_times:
114
  plans.insert_one({
115
  "user_id": acc["user_id"],
116
- "times": schedule_times,
117
  "created": 0
118
  })
119
 
120
- log.info(f"πŸ“… Plans created for today between {now.strftime('%I:%M %p')} and {end_of_day.strftime('%I:%M %p')} IST.")
121
  apply_today_plan()
122
 
123
  try:
@@ -126,7 +124,7 @@ def reset_and_plan():
126
  asyncio.create_task,
127
  bot.send_message(
128
  ADMIN_ID,
129
- f"βœ… Plans reset for today ({now.strftime('%d/%m/%Y')}), all future only.\nNext reset: 00:00 IST"
130
  )
131
  )
132
  except Exception as e:
 
85
  )
86
  def reset_and_plan():
87
  tz = pytz.timezone("Asia/Kolkata")
88
+ plans.delete_many({}) # Clear existing plans
89
+ end_of_day = datetime.now(tz).replace(hour=23, minute=59, second=0, microsecond=0)
 
 
90
 
91
  for acc in accounts.find():
92
  limit = random.randint(3, 5)
93
  times = set()
94
  attempts = 0
95
 
96
+ while len(times) < limit and attempts < 10:
97
+ now = datetime.now(tz).replace(second=0, microsecond=0)
98
  attempts += 1
99
+
100
  minutes_left = int((end_of_day - now).total_seconds() // 60)
101
+ if minutes_left <= 10:
102
+ break # Not enough time left in the day
 
103
 
104
+ random_minutes = random.randint(6, minutes_left) # βœ… At least 6 minutes in future
105
  future_time = now + timedelta(minutes=random_minutes)
106
 
107
+ # Only add if it's at least 5 minutes in the future
108
+ if future_time > now + timedelta(minutes=5):
109
+ times.add(future_time.replace(second=0, microsecond=0))
110
 
111
+ if times:
 
112
  plans.insert_one({
113
  "user_id": acc["user_id"],
114
+ "times": sorted(times),
115
  "created": 0
116
  })
117
 
118
+ log.info("βœ… Today's plans reset with future-safe times.")
119
  apply_today_plan()
120
 
121
  try:
 
124
  asyncio.create_task,
125
  bot.send_message(
126
  ADMIN_ID,
127
+ f"πŸ“Š Plans reset!\nπŸ—“οΈ Date: {datetime.now(tz).strftime('%d/%m/%Y')}\nπŸ•› Next Reset: 24/07/2025 12:00 AM IST"
128
  )
129
  )
130
  except Exception as e: