🐍 python once per hour

python

fukurou

the supreme coder
ADMIN
Python:
from datetime import datetime

class EveningGate:
    def __init__(self):
        self._triggered_today = False
        self._current_day = None
        
    def trigger(self):
        now = datetime.now()
        today = now.date()
        
        if self._current_day != today:
            self._current_day = today
            self._triggered_today = False
            
        if now.hour == 19 and not self._triggered_today:
            self._triggered_today = True
            return True
            
        return False


# Example usage
gate = EveningGate()

# In your code, just call trigger()
if gate.trigger():
    print("It's 7 PM! Time for the evening task!")
 

fukurou

the supreme coder
ADMIN

Python:
from datetime import datetime

class EveningGate:
    def __init__(self, hour=19):
        self.hour = hour
        self._triggered_today = False
        self._current_day = None
        
    def trigger(self):
        now = datetime.now()
        today = now.date()
        
        if self._current_day != today:
            self._current_day = today
            self._triggered_today = False
            
        if now.hour == self.hour and not self._triggered_today:
            self._triggered_today = True
            return True
            
        return False


# Example usage
gate = EveningGate()  # Default 7 PM
# gate = EveningGate(20)  # For 8 PM
# gate = EveningGate(6)   # For 6 AM

if gate.trigger():
    print(f"It's {gate.hour}:00! Time for the task!")
 
Top