Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,147,981 members, 7,799,348 topics. Date: Tuesday, 16 April 2024 at 07:23 PM

Python Code For Birthday Reminder - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Code For Birthday Reminder (4263 Views)

Programmers Writes Code For DAVIDO'S IF Song / Check Out My Python Code For Giving You The Date/time You Are Currently. / Please Help With This Python Code (2) (3) (4)

(1) (Reply) (Go Down)

Python Code For Birthday Reminder by soloyes(m): 9:42pm On May 16, 2015
Please I urgently need help with a python code for birthday reminder with the following features:
I. Sets up a birthday book with some people and their birthday # for testing.
ii. Define a function that prints a person's birthday given the person's name.
iii. Define a function which given a month, prints a list of all the people who have birthdays that month.
iv. Define a function which given a month and a date, prints a list of all the people who have birthdays within the next week, with the dates.
Thank you all in anticipation.
Re: Python Code For Birthday Reminder by Drniyi4u(m): 9:51pm On May 16, 2015
....wįll dęƒįŋįţęly woŗķ oŋ ţђįş
Re: Python Code For Birthday Reminder by soloyes(m): 9:58pm On May 16, 2015
Drniyi4u:
....wįll dęƒįŋįţęly woŗķ oŋ ţђįş
Tnx @Drniyi4u I really appreciate.
Re: Python Code For Birthday Reminder by soloyes(m): 7:54am On May 17, 2015
Keep the codes flowing in
Re: Python Code For Birthday Reminder by soloyes(m): 4:25pm On May 17, 2015
Still waiting
Re: Python Code For Birthday Reminder by adewasco2k(m): 7:08pm On May 17, 2015
i dont get it



You want someone to actually spend time solving your problems?


my candid advice will be for you to go learn python...try to solve the problems and then you can come back if you face any problem
Re: Python Code For Birthday Reminder by Nobody: 10:12pm On May 19, 2015
I will like to help you but i dont time now maybe i give a source. Which you will start from
Re: Python Code For Birthday Reminder by Perhaps: 1:37pm On May 21, 2015
I wrote your code but since am not really frequent on nairaland, I won't be able to upload it.
You can give me your mail or number so I can mail it to you.
Re: Python Code For Birthday Reminder by bomsy1(m): 11:18am On May 22, 2015
You can use these files, just put both in the same folder and run the "birthday_reminder_gui.py" file.... the "backend.py" file can as well be used solely, the gui file was just for fun...
PS: my python is a lil rusty, hope you'll find it useful.
Happy coding smiley

Re: Python Code For Birthday Reminder by jacob05(m): 4:10pm On May 22, 2015
Python, sweet python... would love to help you but it seems it's been a while since post this, hope you've solved it ?
Re: Python Code For Birthday Reminder by jacob05(m): 6:57pm On May 26, 2015
......sorry ....code pasted wrongly
Re: Python Code For Birthday Reminder by jacob05(m): 6:59pm On May 26, 2015


from datetime import datetime, timedelta
import time
from calendar import Calendar

class Person:
def __init__(self, name, birthdate):
self.name = name
self.birthdate = birthdate
def setName(self, name):
self.name = name
def getName(self):
return self.name
def setBirthDate(self, birthdate):
self.birthdate = birthdate
def getBirthDate(self):
return self.birthdate

class BirthdayBook:
def __init__(self, personList = {}):
self.personList = personList
def addPerson(self, person):
self.personList[person.getName()] = person
def _getBirthdayByName(self, name):
if self.personList.get(name):
return self.personList.get(name).getBirthDate()
return None
def _getPersonByBirthDateMonth(self, month):
marches = [];
for p in self.personList.values():
if p.getBirthDate().month == month:
marches.append(p)
return marches
def printBirthDateByName(self, name):
d = self._getBirthdayByName(name)
if d != None:
print("Name:", name,"BirthDate:", d.day, "/" ,d.month ,"/" ,d.year)
return
print("Person Not Found"wink

def printBirthdayByMonth(self, month):
marches = self._getPersonByBirthDateMonth(month)
if marches != []:
print("Persons born in the month ",month)
for p in marches:
print(p.getName())
else:
print("Persons born in the month ",month,"not in DB"wink
def _getPersonsBirthdayWithinTheWeek(self, month, day):
#This function is assuming
#Monday as the first day of week and sunday as the last day .. wink
marches = [];
currentDatetime = datetime.now()
userDateWeekday = datetime(currentDatetime.year,month,day).weekday()
#If for the whole week
#firstWeekdayTimestamp = datetime(currentDatetime.year,month,day) - timedelta(userDateWeekday)).timestamp()
firstWeekdayTimestamp = datetime(currentDatetime.year,month,day).timestamp()
lastWeekdayTimestamp = (datetime(currentDatetime.year,month,day) + timedelta(6 - userDateWeekday)).timestamp()
for p in self.personList.values():
pBirthDate = p.getBirthDate()
if pBirthDate.month == month:
pBirthDate = datetime(currentDatetime.year,pBirthDate.month,pBirthDate.day)
ptimestamp = pBirthDate.timestamp()
if ptimestamp >= firstWeekdayTimestamp and ptimestamp <= lastWeekdayTimestamp:
marches.append(p)
return marches
def printBirthdayWithinTheWeek(self, month, day):
marches = self._getPersonsBirthdayWithinTheWeek(month,day)
if marches != []:
print("Persons born within the week of ",month,day)
for p in marches:
print(p.getName())
else:
print("Persons born within the week of ",month,day,"not in DB"wink
if __name__ == '__main__':
person1 = Person("Jacob", datetime(1900,5,25))
person2 = Person("John", datetime(1900,5,18))
person3 = Person("Mayowa", datetime(1900,5,23))
person4 = Person("Xeun", datetime(1900,5,21))
person5 = Person("Phil", datetime(1900,2,21))
person6 = Person("Dayo", datetime(1900,5,5))
birthdayBook=BirthdayBook()
birthdayBook.addPerson(person1)
birthdayBook.addPerson(person2)
birthdayBook.addPerson(person3)
birthdayBook.addPerson(person4)
birthdayBook.addPerson(person5)
birthdayBook.addPerson(person6)
birthdayBook.printBirthDateByName("Jacob"wink
birthdayBook.printBirthdayByMonth(2)
birthdayBook.printBirthdayWithinTheWeek(5,20)








Re: Python Code For Birthday Reminder by jacob05(m): 9:27am On May 27, 2015
hope it helps
Re: Python Code For Birthday Reminder by soloyes(m): 4:11pm On May 27, 2015
Thank U all for your wonderful contributions especially @bomsy and @Jacob05. I was able to find my way through though.
The major problem with the exercise was that we weren't allowed to use predefined functions like the calendar function but were required to create ours. After much struggle I discovered that also wasn't as tough as earlier anticipated. Thank you all

(1) (Reply)

Goodbye Java! / Developing A Facebook-like Ticker For Nairaland / Internships With Google

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.