Update app.py
Browse files
app.py
CHANGED
|
@@ -85,39 +85,37 @@ def apply_today_plan():
|
|
| 85 |
)
|
| 86 |
def reset_and_plan():
|
| 87 |
tz = pytz.timezone("Asia/Kolkata")
|
| 88 |
-
|
| 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 <
|
|
|
|
| 99 |
attempts += 1
|
|
|
|
| 100 |
minutes_left = int((end_of_day - now).total_seconds() // 60)
|
| 101 |
-
if minutes_left <=
|
| 102 |
-
|
| 103 |
-
break
|
| 104 |
|
| 105 |
-
random_minutes = random.randint(
|
| 106 |
future_time = now + timedelta(minutes=random_minutes)
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
if future_time > now:
|
| 110 |
-
times.add(future_time)
|
| 111 |
|
| 112 |
-
|
| 113 |
-
if schedule_times:
|
| 114 |
plans.insert_one({
|
| 115 |
"user_id": acc["user_id"],
|
| 116 |
-
"times":
|
| 117 |
"created": 0
|
| 118 |
})
|
| 119 |
|
| 120 |
-
log.info(
|
| 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"
|
| 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:
|