soxogvv commited on
Commit
9bbffa6
Β·
verified Β·
1 Parent(s): f279fbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -56,7 +56,7 @@ def create_plan(account, limit):
56
  times = []
57
  for i in range(limit):
58
  planned_time = now + i * time_gap
59
- # Ensure future time
60
  if planned_time <= now:
61
  planned_time = now + timedelta(minutes=1)
62
  times.append(planned_time)
@@ -66,9 +66,12 @@ def create_plan(account, limit):
66
  "account_id": account["_id"],
67
  "scheduled_time": t.isoformat()
68
  })
 
 
69
 
70
  def apply_plan():
71
  now = datetime.now(tz)
 
72
  for plan in plans.find():
73
  plan_time = datetime.fromisoformat(plan["scheduled_time"]).astimezone(tz)
74
  if plan_time > now:
@@ -78,19 +81,25 @@ def apply_plan():
78
 
79
  userbot = userbots.get(account["_id"])
80
  if not userbot:
 
81
  continue
82
 
83
  def job_wrapper(acc_id):
84
  def job():
85
- print(f"Running job for account {acc_id} at {datetime.now(tz)}")
86
- # Your action here
87
  return job
88
 
89
- scheduler.add_job(job_wrapper(account["_id"]), trigger='date', run_date=plan_time)
 
 
 
 
 
90
 
91
  def reset_and_plan():
92
  print("πŸ” Resetting plans and scheduling new ones...")
93
- plans.delete_many({}) # Clear all plans
94
  for acc in accounts.find():
95
  limit = random.randint(3, 5)
96
  create_plan(acc, limit)
 
56
  times = []
57
  for i in range(limit):
58
  planned_time = now + i * time_gap
59
+ # Ensure it's a future time (at least 1 minute ahead)
60
  if planned_time <= now:
61
  planned_time = now + timedelta(minutes=1)
62
  times.append(planned_time)
 
66
  "account_id": account["_id"],
67
  "scheduled_time": t.isoformat()
68
  })
69
+ print(f"βœ… Created {len(times)} plan(s) for account {account['_id']}")
70
+
71
 
72
  def apply_plan():
73
  now = datetime.now(tz)
74
+ count = 0
75
  for plan in plans.find():
76
  plan_time = datetime.fromisoformat(plan["scheduled_time"]).astimezone(tz)
77
  if plan_time > now:
 
81
 
82
  userbot = userbots.get(account["_id"])
83
  if not userbot:
84
+ print(f"⚠️ No userbot for account {account['_id']}, skipping...")
85
  continue
86
 
87
  def job_wrapper(acc_id):
88
  def job():
89
+ print(f"πŸ•’ Running job for account {acc_id} at {datetime.now(tz)}")
90
+ # Put your real logic here
91
  return job
92
 
93
+ job_id = f"job_{plan['_id']}"
94
+ scheduler.add_job(job_wrapper(account["_id"]), trigger='date', run_date=plan_time, id=job_id)
95
+ print(f"πŸ“Œ Scheduled job for account {account['_id']} at {plan_time.strftime('%H:%M:%S')} (ID: {job_id})")
96
+ count += 1
97
+ print(f"βœ… Applied and scheduled {count} job(s).")
98
+
99
 
100
  def reset_and_plan():
101
  print("πŸ” Resetting plans and scheduling new ones...")
102
+ plans.delete_many({})
103
  for acc in accounts.find():
104
  limit = random.randint(3, 5)
105
  create_plan(acc, limit)