-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from sudiptob2/refactor/41-strict-flake8
Refactor/41 strict flake8
- Loading branch information
Showing
12 changed files
with
444 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
pyclean() { | ||
# Cleaning cache: | ||
find . | | ||
grep -E '(__pycache__|\.hypothesis|\.perm|\.cache|\.static|\.py[cod]$)' | | ||
xargs rm -rf | ||
} | ||
|
||
run_checks() { | ||
echo '[Check Started]' | ||
set -x # we want to print commands during the CI process. | ||
|
||
# Running linting for all python files in the project: | ||
python -m flake8 | ||
|
||
# Running type checking, see https://github.com/typeddjango/django-stubs | ||
python -m mypy leeteasy tests | ||
|
||
# Running tests: | ||
python -m pytest --cov | ||
|
||
# Checking dependencies status: | ||
python -m pip check | ||
|
||
set +x | ||
echo '[checks completed]' | ||
} | ||
|
||
# Remove any cache before the script: | ||
pyclean | ||
|
||
# Clean everything up: | ||
trap pyclean EXIT INT TERM | ||
|
||
# Run the CI process: | ||
run_checks |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ class Constant: | |
|
||
# http call retries | ||
HTTP_CALL_RETRIES = 3 | ||
|
||
# default sleep duration | ||
DEFAULT_SLEEP = 3600 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
from typing import List | ||
from typing import Dict, List, Optional | ||
|
||
|
||
class Challenge: | ||
"""Singleton Model class for daily challenge.""" | ||
|
||
title: str = '' | ||
raw_tags: List[dict] = None | ||
raw_tags: List[Dict[str, str]] = [] | ||
ac_rate: float = 0 | ||
difficulty: str = None | ||
question_id: int = None | ||
difficulty: str = '' | ||
question_id: int = 0 | ||
title_slug: str = '' | ||
date: str = None | ||
date: str = '' | ||
|
||
def __new__(cls): | ||
if not hasattr(cls, 'instance'): | ||
cls.instance = super(Challenge, cls).__new__(cls) | ||
"""Override default class creation logic.""" | ||
if not hasattr(cls, 'instance'): # NOQA : WPS421 | ||
cls.instance = super(Challenge, cls).__new__(cls) # NOQA: WPS608 | ||
return cls.instance | ||
|
||
@property | ||
def problem_link(self) -> str: | ||
"""Returns the link of the problem.""" | ||
"""Return the link of the problem.""" | ||
return 'https://leetcode.com/problems/{0}/'.format( | ||
self.title_slug, | ||
) | ||
|
||
@property | ||
def tags(self) -> List[str]: | ||
"""Returns the link of the problem.""" | ||
def tags(self) -> List[Optional[str]]: | ||
"""Return the link of the problem.""" | ||
tags = [] | ||
for tag in self.raw_tags: | ||
tags.append(tag.get('name')) | ||
return tags | ||
|
||
def __str__(self): | ||
"""Returns the string rep of the class.""" | ||
return f"Title: {self.title}\nAcceptance Rate: {self.ac_rate}" \ | ||
f"\nDifficulty: {self.difficulty}\n" + \ | ||
f"id: {self.question_id}\nTags: {self.tags}" | ||
"""Return the string rep of the class.""" | ||
return 'Title: {0}\nAcceptance: {1}\nDifficulty: {2}\nID: {3}\nTags: {4}\n'.format( | ||
self.title, | ||
self.ac_rate, | ||
self.difficulty, | ||
self.question_id, | ||
self.tags, | ||
) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
from typing import Dict | ||
|
||
from leeteasy.models.challenge import Challenge | ||
|
||
|
||
class RequestParser: | ||
"""Parse responses of leetcode API.""" | ||
|
||
@classmethod | ||
def parse(cls, challenge_info: dict) -> Challenge: | ||
def parse(cls, challenge_info: Dict) -> Challenge: | ||
"""Parse API data ans update challenge model.""" | ||
return RequestParser._parse_challenge_info(challenge_info) | ||
return cls._parse_challenge_info(challenge_info) | ||
|
||
@classmethod | ||
def _parse_challenge_info(cls, challenge_info) -> Challenge: | ||
"""Parse and update challenge model.""" | ||
question = challenge_info.get('question') | ||
challenge = Challenge() | ||
challenge.title = challenge_info.get('question').get('title') | ||
challenge.ac_rate = challenge_info.get('question').get('acRate') | ||
challenge.difficulty = challenge_info.get('question').get('difficulty') | ||
challenge.question_id = challenge_info.get('question').get('frontendQuestionId') | ||
challenge.title = question.get('title') | ||
challenge.ac_rate = question.get('acRate') | ||
challenge.difficulty = question.get('difficulty') | ||
challenge.question_id = question.get('frontendQuestionId') | ||
challenge.date = challenge_info.get('date') | ||
challenge.title_slug = challenge_info.get('question').get('titleSlug') | ||
challenge.raw_tags = challenge_info.get('question').get('topicTags') | ||
challenge.title_slug = question.get('titleSlug') | ||
challenge.raw_tags = question.get('topicTags') | ||
return challenge |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.