def get_time_string(contest, contest_type): """Return a string with time for the contest to begin/end""" if contest_type == challenge().ACTIVE: time_diff = time_difference(contest["end"]) elif contest_type == challenge().UPCOMING: time_diff = time_difference(contest["start"]) elif contest_type in [ challenge().HIRING, challenge().SHORT, challenge().ALL ]: try: time_diff = time_difference(contest["start"]) except: time_diff = time_difference(contest["end"]) time_diff_string = "" if time_diff.days > 0: time_diff_string = "{0} days {1} hours".format(time_diff.days, time_diff.hours) elif time_diff.hours > 0: time_diff_string = "{0} hours {1} minutes".format( time_diff.hours, time_diff.minutes) else: time_diff_string = "{0} minutes".format(time_diff.minutes) return time_diff_string
def upcoming_contests(platforms, time): """Gets all the upcoming contests based on time and platforms""" contests_data = get_contests_data() platform_filter = get_platform_filter(platforms) upcoming_challenges = [contest for contest in contests_data["pending"] if contest["host_name"] in platform_filter and time_difference(contest["start"]).days <= time] return upcoming_challenges
def get_time_string(contest, contest_type): """Return a string with time for the contest to begin/end""" if contest_type == challenge().ACTIVE: time_diff = time_difference(contest["end"]) elif contest_type == challenge().UPCOMING: time_diff = time_difference(contest["start"]) elif contest_type in [challenge().HIRING, challenge().SHORT, challenge().ALL]: try: time_diff = time_difference(contest["start"]) except: time_diff = time_difference(contest["end"]) time_diff_string = "" if time_diff.days > 0: time_diff_string = "{0} days {1} hours".format(time_diff.days, time_diff.hours) elif time_diff.hours > 0: time_diff_string = "{0} hours {1} minutes".format(time_diff.hours, time_diff.minutes) else: time_diff_string = "{0} minutes".format(time_diff.minutes) return time_diff_string
def upcoming_contests(platforms, time): """Gets all the upcoming contests based on time and platforms""" contests_data = get_contests_data() if platforms: platform_filter = [PLATFORM_IDS[x] for x in platforms] else: platform_filter = PLATFORM_IDS.values() upcoming_challenges = [contest for contest in contests_data["pending"] if contest["host_name"] in platform_filter and time_difference(contest["start"]).days <= time] return upcoming_challenges
def get_all_contests(platforms, time): """Gets all the contests and writes it to standard output""" contests_data = get_contests_data() active_contests = contests_data["active"] upcoming_contests = contests_data["pending"] platform_filter = get_platform_filter(platforms) contests_data = [contest for contest in active_contests if contest["host_name"] in platform_filter] contests_data += [contest for contest in upcoming_contests if contest["host_name"] in platform_filter and time_difference(contest["start"]).days <= time] return contests_data
def get_all_contests(platforms, time): """Gets all the contests and writes it to standard output""" contests_data = get_contests_data() active_contests = contests_data["active"] upcoming_contests = contests_data["pending"] if platforms: platform_filter = [PLATFORM_IDS[x] for x in platforms] else: platform_filter = PLATFORM_IDS.values() contests_data = [contest for contest in active_contests if contest["host_name"] in platform_filter] contests_data += [contest for contest in upcoming_contests if contest["host_name"] in platform_filter and time_difference(contest["start"]).days <= time] return contests_data