coredumped0x
coredumped0x

Reputation: 848

Generate a sorted list of birthday dates and append each date to a newline in a file

So, I have been trying to generate a wordlist with birthday dates. I am trying to append each value to a newline in a file birdthday_wordlist.txt. The file and the format should be like this:

01/01/1998
02/01/1998
03/01/1998
dd/mm/yyyy
12/12/2000

I was capable of generating only the dd, mm or yyyy, with scripts like this:

with open('XXXXXX_wordlist.txt', 'w') as birdthday_wordlist:
for i in range(1980, 2000):
    birdthday_wordlist.write('{}\n'.format(i))

I know there is a way, for now I couldn't figure it out.

Upvotes: 0

Views: 1244

Answers (3)

natn2323
natn2323

Reputation: 2061

If you want a solution that doesn't use imported packages, you can do the following:

data = []
f_string = "%02d/%02d/%04d\n" # Will be presented as dd/mm/yyyy format

for year in range(1980, 2000):
    for month in range(1, 12):
        for day in range(1, 31):
            data.append(f_string % (day, month, year))

with open('XXXXXX_wordlist.txt', 'w') as birthday_wordlist:    
    for item in data:
        birthday_wordlist.write(item)

Upvotes: 0

Ethan Brews
Ethan Brews

Reputation: 131

If I understand what you're asking, it's very similar to the question here

I have adapted the answer to write the dates to a file:

from datetime import timedelta, date

def daterange(start_date, end_date):
    for n in range(int ((end_date - start_date).days)):
        yield start_date + timedelta(n)

start_date = date(1980, 1, 1)
end_date = date(2000, 1, 1)
with open('XXXXXX_wordlist.txt', 'w+') as birdthday_wordlist:
    for single_date in daterange(start_date, end_date):
        birdthday_wordlist.write('%s\n' % single_date.strftime("%d/%m/%Y"))

Will output:

01/01/1980
02/01/1980
03/01/1980
04/01/1980
05/01/1980
...
31/12/1999

Upvotes: 0

nacho
nacho

Reputation: 5397

You can use a while and the datetime functions. You can set the ini date as you need, and the end date you want. It will sum 1 day each iteration

import datetime

ini=datetime.date(year=1980,month=1,day=1)
end=datetime.date(year=2000,month=1,day=1)
while ini<=end:
    birdthday_wordlist.write(ini.strftime('%d/%m/%Y')+'\n')
    ini=ini+datetime.timedelta(days=1)

Upvotes: 0

Related Questions