Created
September 2, 2018 14:53
-
-
Save ltbringer/59ad870b6f09f65e442812c9073dfa51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
month_map = { | |
'january': 1, | |
'february': 2, | |
'march': 3, | |
'april': 4, | |
'may': 5, | |
'june': 6, | |
'july': 7, | |
'august': 8, | |
'september': 9, | |
'october': 10, | |
'november': 11, | |
'december': 12 | |
} | |
month_short = { | |
'jan':'january', | |
'feb':'february', | |
'mar':'march', | |
'apr':'april', | |
'may':'may', | |
'jun':'june', | |
'jul':'july', | |
'aug':'august', | |
'sept':'september', | |
'oct':'october', | |
'nov':'november', | |
'dec':'december' | |
} | |
calendar_days = list(range(1, 32)) | |
days_of_week = { | |
'monday': 0, | |
'tuesday': 1, | |
'wednesday': 2, | |
'thursday': 3, | |
'friday': 4, | |
'saturday': 5, | |
'sunday': 6 | |
} | |
short_day_name = { | |
'mon': 'monday', | |
'tue': 'tuesday', | |
'wed': 'wednesday', | |
'thu': 'thursday', | |
'fri': 'friday', | |
'sat': 'saturday', | |
'sun': 'sunday' | |
} | |
day_subscripts = { | |
'1': 'st', | |
'2': 'nd', | |
'3': 'rd'' | |
} | |
def title_case(string): | |
return string[0].upper() + string[1:] | |
def zero_padding(number): | |
return '0{}'.format(number) if number < 10 else str(number) | |
def date_subscript(number): | |
return 'th'\ | |
if int(number) > 10 and int(number) < 20 \ | |
else day_subscripts.get(str(number)[-1], 'th') | |
def random_date_generator(): | |
random_year = random.randint(2018, 2020) | |
delimiters = [' '] | |
month_reps = list(month_map.keys()) + list(month_short.keys()) | |
random_month_string = random.choice(month_reps) | |
if random.random() > 0.5: | |
random_month = random_month_string if random.random() > 0.5 else title_case(random_month_string) | |
else: | |
random_month = str(month_map.get(random_month_string, 1)) | |
delimiters.extend(['-', '/']) | |
random_day = random.choice(calendar_days) | |
random_day = zero_padding(random_day) if random.random() > 0.5 else str(random_day) | |
random_day_subscript = date_subscript(random_day) if random.random() > 0.5 else '' | |
random_delimiter = random.choice(delimiters) | |
return '{random_day}{random_day_subscript}{delimiter}{random_month}{delimiter}{random_year}'.format( | |
random_day=random_day, | |
random_day_subscript=random_day_subscript, | |
delimiter=random_delimiter, | |
random_month=random_month, | |
random_year=random_year | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment