Automatic Birthday Wisher Using Python

By Himanshu Patel Last Updated 48 Days Ago 4 Minutes Read Technology 0
Smart Entrepreneurs

Python Automatic Birthday Wisher: An easy-to-use program to make sure you never forget a birthday. It uses plyer for desktop alerts and pywhatkit for WhatsApp to send customized messages. It’s useful and considerate at the same time, adding a personal touch to your greetings with customizable messages and scheduled sending. 

What is Python? 

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. 

Must Read: Why you should invest in Responsive Web Design Services

How can we make birthday wishes using Python? 

Birthday is one of the happiest days in the life of every human being. Everyone hopes that on this day his/her loved ones will uniquely greet him/her. Some give a sudden surprise, some people wish by eye-catching gifts, etc. 

But as a Python programmer, an idea strikes to my mind. I thought if a Python program could be created to wish someone automatically where we could customize the birthday message and time as well. It would be great, wouldn’t it? 

Today, you will learn to wish someone Happy Birthday in Python Code. You just need to add details of that person in a file. 

This code is simpler than you think and very surprising. You have to install two packages or modules that are ‘plyer’ and ‘pywhatkit’.

 

To install you have to type the following commands in the terminal. 

pip install plyer 

pip install pywhatkit 

bdayfile.txt 

Automatic Birthday Wisher

This format will allow the script to parse both the name and phone number correctly for sending birthday wishes. 

Code: 

from datetime import datetime 

from plyer import notification 

import time 

import pywhatkit 

# Path of file 

bdayfile = r’D:\Birthdaywish\bdayfile.txt’ 

  

def birthdayReminder(): 

    today = time.strftime(‘%d%m’)  # Get today’s date in ‘ddmm’ format 

    bday = False 

  

    # Open the file and read it line by line 

    with open(bdayfile, “r”) as file: 

        for line in file: 

            if today in line:  # Check if today’s date matches a birthday in the file 

                bday_data = line.split(‘ ‘)  # Assuming format: ‘ddmmyyyy Name’ 

                bday_name = bday_data[1]     # Extract name (after splitting by space) 

                bday_phone = bday_data[2]    # Extract phone number (if added in the file) 

                bday = True 

  

                # Trigger the notification 

                notification.notify( 

                    title=”Birthday Reminder!”, 

                    message=f”Wish {bday_name} a happy birthday!”, 

                    app_name=’Automatic Birthday Wisher’, 

                    # app_icon=r”C:\\path\\to\\icon.ico”,  # Uncomment if you have an icon 

                    timeout=5  # Notification timeout 

                ) 

  

                # Send a WhatsApp message via pywhatkit 

                # now = datetime.now() 

                # # Schedule message for 1 minute later 

                # pywhatkit.sendwhatmsg(bday_phone, f”Happy Birthday, {bday_name}!”, now.hour, (now.minute + 1)) 

  

                # Send a WhatsApp message via pywhatkit 

                now = datetime.now() 

                 

                # Add a buffer time (e.g., 2 minutes from now) 

                future_minute = (now.minute + 2) % 60 

                future_hour = now.hour + (now.minute + 2) // 60  # Adjust hour if minute goes past 60 

                pywhatkit.sendwhatmsg(bday_phone, f”Happy Birthday, {bday_name}!”, future_hour, future_minute) 

                # # Schedule message for 1 minute later 

                # pywhatkit.sendwhatmsg(bday_phone, f”Happy Birthday, {bday_name}!”, now.hour, (now.minute + 1)) 

                # Optional: Send a WhatsApp message via pywhatkit 

                # pywhatkit.sendwhatmsg(“+1234567890″, f”Happy Birthday, {bday_name}!”, 12, 0) 

    if not bday: 

        print(“No birthdays today.”) 

if __name__ == “__main__”: 

    birthdayReminder() 

When you will run the code a notification will be popped up on the desktop screen and a message will be sent to that person on WhatsApp whom you will add into bdayfile.txt. 

Birthday wishes 2

Birthday wishes 3

Conclusion: 

This Python project automates birthday wishes, providing personalized messages to friends and loved ones. It uses the plyer library for desktop notifications and pywhatkit for WhatsApp messages, requiring only a text file with birthdays. It combines practicality and creativity. 

Social Media :

Join 10,000 subscribers!

Join Our subscriber’s list and trends, especially on mobile apps development.

I hereby agree to receive newsletters from Mobmaxime and acknowledge company's Privacy Policy.