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
# This's a automatic birthday wisher program. # A birthday message will be sent automatically to a particular person whom will add in 'bdayfile.txt' # Note : Pls take care of the format when you add someone's details in 'bdayfile.txt' # Feel free to ask if have any doubt... from datetime import datetime from plyer import notification import time import pywhatkit # Path of file bdayfile = r'D:\\Python\\Project\\bdayfile.txt' def birthdayReminder(): filename = open(bdayfile, "r") today = time.strftime('%d%m') # read date and month bday = False for bday_date in filename: if today in bday_date: bday_date = bday_date.split(' ') bday = True if __name__ == "__main__": notification.notify( title="Birthday Reminder!", message='''"Wishing a happy birthday!"''', app_name = 'Automatic Birthday Wisher', app_icon=r"C:\\Users\\shami_20topwo\\Downloads\\Juliewiens-Christmas-Gift.ico", #Path of icon which will appear in notification timeout=3 ) if bday == True :
#Syntax: pywhatkit.sendmsg(“receiver mobile number”,”message”,hours,minutes) # Parameters: # Receiver mobile number: The Receiver’s mobile number must be in string format and the country code must be mentioned before the mobile number. # Message: Message to be sent(Must be in string format). # Hours: This module follows the 24 hrs time format. # Minutes: Mention minutes of the scheduled time for the message(00-59) pywhatkit.sendwhatmsg(bday_date, "Happy birthday dear!", 23, 59) # 24 hrs time format 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 following bdayfile.txt.
Note: A message will be sent at the specified time. Here I wanted to take a screenshot so I had to change the time to 5:38 PM. In your case, you can customize it accordingly.