help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
slack-bot-assistant
/
bot
RSK World
slack-bot-assistant
Slack Bot Assistant - Python + Slack API + SQLite + PHP Dashboard + Bot Commands + Automation
bot
  • __pycache__
  • app.py30.8 KB
  • config.py1.9 KB
  • helpers.py5.5 KB
  • models.py4.4 KB
  • scheduler.py3.1 KB
  • utils.py12.6 KB
scheduler.py
bot/scheduler.py
Raw Download
Find: Go to:
"""
Slack Bot Assistant - Advanced Scheduler
Developer: Molla Samser (Founder, RSK World)
Design & Testing: Rima Khatun
Website: https://rskworld.in
Contact: hello@rskworld.in | +91 93305 39277
Year: 2026
"""

import schedule
import threading
import time
from datetime import datetime, timedelta
from typing import Callable, Optional

class TaskScheduler:
    """Advanced task scheduler for recurring tasks"""
    
    def __init__(self):
        self.running = False
        self.thread = None
        self.tasks = []
    
    def add_daily_task(self, time_str: str, task_func: Callable, *args, **kwargs):
        """Add a daily recurring task"""
        schedule.every().day.at(time_str).do(task_func, *args, **kwargs)
        self.tasks.append({
            "type": "daily",
            "time": time_str,
            "function": task_func.__name__ if hasattr(task_func, '__name__') else str(task_func)
        })
    
    def add_hourly_task(self, task_func: Callable, *args, **kwargs):
        """Add an hourly recurring task"""
        schedule.every().hour.do(task_func, *args, **kwargs)
        self.tasks.append({
            "type": "hourly",
            "function": task_func.__name__ if hasattr(task_func, '__name__') else str(task_func)
        })
    
    def add_weekly_task(self, day: str, time_str: str, task_func: Callable, *args, **kwargs):
        """Add a weekly recurring task"""
        day_map = {
            "monday": schedule.every().monday,
            "tuesday": schedule.every().tuesday,
            "wednesday": schedule.every().wednesday,
            "thursday": schedule.every().thursday,
            "friday": schedule.every().friday,
            "saturday": schedule.every().saturday,
            "sunday": schedule.every().sunday
        }
        day_lower = day.lower()
        if day_lower in day_map:
            day_map[day_lower].at(time_str).do(task_func, *args, **kwargs)
            self.tasks.append({
                "type": "weekly",
                "day": day,
                "time": time_str,
                "function": task_func.__name__ if hasattr(task_func, '__name__') else str(task_func)
            })
    
    def _run_pending(self):
        """Internal method to run pending tasks"""
        while self.running:
            schedule.run_pending()
            time.sleep(60)  # Check every minute
    
    def start(self):
        """Start the scheduler"""
        if not self.running:
            self.running = True
            self.thread = threading.Thread(target=self._run_pending, daemon=True)
            self.thread.start()
    
    def stop(self):
        """Stop the scheduler"""
        self.running = False
        schedule.clear()
    
    def get_pending_tasks(self):
        """Get list of pending tasks"""
        return schedule.jobs
    
    def get_task_list(self):
        """Get list of registered tasks"""
        return self.tasks

# Global scheduler instance
scheduler = TaskScheduler()

def init_scheduler():
    """Initialize and start the scheduler"""
    scheduler.start()
    return scheduler

96 lines•3.1 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer