Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make local imports relative #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions challenges/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import requests
import click

from local_exceptions import IncorrectParametersException
from .local_exceptions import IncorrectParametersException

import writers
from . import writers

from platformids import platforms as contest_platforms
from utilities import time_difference
from .platformids import platforms as contest_platforms
from .utilities import time_difference

BASE_URL = "http://challengehuntapp.appspot.com/v2"
PLATFORM_IDS = contest_platforms

def check_platforms(platforms):
"""Checks if the platforms have a valid platform code"""
if len(platforms) > 0:
return all(platform in PLATFORM_IDS for platform in platforms):
return all(platform in PLATFORM_IDS for platform in platforms)
return True


Expand Down Expand Up @@ -47,14 +47,14 @@ def active_contests(platforms):
active_challenges = [contest for contest in contests_data["active"] if contest["host_name"] in platform_filter]

return active_challenges


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
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
Expand Down Expand Up @@ -96,9 +96,9 @@ def get_all_contests(platforms, time):

platform_filter = get_platform_filter(platforms)

contests_data = [contest for contest in active_contests
contests_data = [contest for contest in active_contests
if contest["host_name"] in platform_filter]
contests_data += [contest for contest in upcoming_contests
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

Expand Down
2 changes: 1 addition & 1 deletion challenges/local_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class IncorrectParametersException(Exception):
pass
pass
12 changes: 6 additions & 6 deletions challenges/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

from utilities import time_difference
from .utilities import time_difference

def colors():
"""Creates an enum for colors"""
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_time_string(contest, contest_type):
time_diff = time_difference(contest["end"])
time_diff_string = ""

if time_diff.days > 0:
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)
Expand All @@ -75,11 +75,11 @@ def get_time_string(contest, contest_type):
def write_contest_header(contest_type):
"""Prints the header for the type of contest"""
if contest_type == challenge().ACTIVE:
click.secho("%-3s %-50s %-20s %-11s %-15s" %
click.secho("%-3s %-50s %-20s %-11s %-15s" %
("NO.", "NAME", "ENDS IN", "DURATION", "PLATFORM"))
elif contest_type == challenge().UPCOMING:
click.secho("%-3s %-50s %-20s %-11s %-15s" %
click.secho("%-3s %-50s %-20s %-11s %-15s" %
("NO.", "NAME", "STARTS IN", "DURATION", "PLATFORM"))
elif contest_type in [challenge().HIRING, challenge().SHORT, challenge().ALL]:
click.secho("%-3s %-50s %-20s %-11s %-15s" %
("NO.", "NAME", "STARTS/ENDS IN", "DURATION", "PLATFORM"))
click.secho("%-3s %-50s %-20s %-11s %-15s" %
("NO.", "NAME", "STARTS/ENDS IN", "DURATION", "PLATFORM"))