Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I determine zodiac / astrological star sign from a birthday in Python?

I am building a dating site in Django / Python. I have birthday dates and need to show what the person's Zodiac sign is based on their birthday.

Anybody done this before? What would be the most efficient way of accomplishing this?

like image 508
rwdsco Avatar asked Jul 18 '10 06:07

rwdsco


1 Answers

I've done this before. The simplest solution that I ended up with was an array of the following key/values:

120:Cap, 218:Aqu, 320:Pis, 420:Ari, 521:Tau,
621:Gem, 722:Can, 823:Leo, 923:Vir, 1023:Lib
1122:Sco, 1222:Sag, 1231: Cap

Then you write the birth date in the mdd format, ie, month number (starting with 1 for January) and two digit day number (01-31). Iterate through the array, and if the date is less than or equal to an item in the array, you have your star sign.

EDIT I needed this so here's this concept as a working function

zodiacs = [(120, 'Cap'), (218, 'Aqu'), (320, 'Pis'), (420, 'Ari'), (521, 'Tau'),
           (621, 'Gem'), (722, 'Can'), (823, 'Leo'), (923, 'Vir'), (1023, 'Lib'),
           (1122, 'Sco'), (1222, 'Sag'), (1231, 'Cap')]
def get_zodiac_of_date(date):
    date_number = int("".join((str(date.date().month), '%02d' % date.date().day)))
    for z in zodiacs:
        if date_number <= z[0]:
            return z[1]
like image 197
bluesmoon Avatar answered Oct 11 '22 02:10

bluesmoon