Search code examples
pythontelegram-botpython-telegram-bot

telegram bot python specific day automated messages


Context: I want to add an automated message in my telegram bot i did with python that will send a message every time a specific holiday is eligible. For example, international mans day, independance day etc. Is this possible without using a json file? Preferably with a simple if function that will compare the current date with a specified one from a list and return a message according to date? I am new in Python if you can direct me to some documentation with an example i would appreciate it:)


Solution

  • If the number of the special holidays is not too high, you could put the dates and the messages inline in the script like so:

    from datetime import date
    
    messages = {
        "03-20": "A message for March Equinox here",
        "09-22": "A message for September Equinox here"
    }
    
    
    def get_message():
        mm_dd = date.today().strftime("%m-%d")
        return messages.get(mm_dd)
    
    
    print(get_message())
    

    If get_message returns something other than None, pass it to the Telegram bot. Run this from cron once a day.