Skip to content

Commit 75c6158

Browse files
authored
Merge branch 'main' into main
2 parents 2e812a1 + 4f1f538 commit 75c6158

File tree

16 files changed

+546
-85
lines changed

16 files changed

+546
-85
lines changed

.github/check.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
pyclean() {
7+
# Cleaning cache:
8+
find . |
9+
grep -E '(__pycache__|\.hypothesis|\.perm|\.cache|\.static|\.py[cod]$)' |
10+
xargs rm -rf
11+
}
12+
13+
run_checks() {
14+
echo '[Check Started]'
15+
set -x # we want to print commands during the CI process.
16+
17+
# Running linting for all python files in the project:
18+
python -m flake8
19+
20+
# Running type checking, see https://github.com/typeddjango/django-stubs
21+
python -m mypy leeteasy tests
22+
23+
# Running tests:
24+
python -m pytest --cov
25+
26+
# Checking dependencies status:
27+
python -m pip check
28+
29+
set +x
30+
echo '[checks completed]'
31+
}
32+
33+
# Remove any cache before the script:
34+
pyclean
35+
36+
# Clean everything up:
37+
trap pyclean EXIT INT TERM
38+
39+
# Run the CI process:
40+
run_checks

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Test
2+
on:
3+
pull_request:
4+
types: [ready_for_review]
5+
6+
jobs:
7+
test:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ ubuntu-latest, macOS-latest]
12+
python-version: [ '3.8', '3.9', '3.10' ]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Python ${{ matrix.python-version }}
18+
id: setup-python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Python version
24+
run: python -c "import sys; print(sys.version)"
25+
26+
# Install pipenv
27+
- name: Install pipenv
28+
run: python3 -m pip install --upgrade pipenv
29+
30+
# create .venv folder
31+
- name: create .venv folder
32+
run: mkdir -p .venv
33+
34+
# caching dependencies
35+
- name: Caching Dependencies
36+
uses: actions/cache@v2
37+
id: cache-dependencies
38+
with:
39+
path: .venv
40+
key: ${{ matrix.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
41+
42+
# install dependencies
43+
- name: Install dependencies
44+
if: steps.cache-dependencies.outputs.cache-hit != 'true'
45+
run: |
46+
pipenv install --dev --verbose
47+
pipenv install types-requests --dev
48+
# Run bash script
49+
- name: run Bash script
50+
run: pipenv run bash ./.github/check.sh

Pipfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ notify-py = "*"
1313
flake8 = "*"
1414
pytest = "*"
1515
pytest-mock = "*"
16+
mypy = "*"
17+
darglint = "*"
18+
flake8-docstrings = "*"
19+
wemake-python-styleguide = "*"
20+
flake8-pytest-style = "*"
21+
flake8-bandit = "*"
22+
pytest-cov = "*"
1623

1724
[requires]
1825
python_version = "3.8"

Pipfile.lock

Lines changed: 275 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ crontab -e
4444
@reboot python -m leeteasy start 14:30 &
4545

4646
```
47-
## Contribution guideline
47+
## Contributing
4848

49-
If you like this project and want to improve by adding features, fixing bugs or anything, please follow
50-
the [contributing guidelines](docs/CONTRIBUTING.md).
49+
We are very happy to see you here. Before sending your pull requests, make sure that you read the whole workflow and the naming conventions mentioned in the [contributing guidelines](docs/CONTRIBUTING.md).
50+
51+
If you have any doubts regarding the contributing guidelines, please feel free to [state it clearly in an issue](https://github.com/sudiptob2/leet-easy/issues/new/choose). All the best!

docs/CONTRIBUTING.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
1+
Given below is the general workflow we expect you to follow while making contributions to this project.
2+
3+
4+
### Workflow
5+
1. Go to the issues tab and find an issue you would like to work on.
6+
7+
1.1. Clarify any doubts in the comments section of the issue.
8+
9+
2. Fork the project
10+
11+
3. Create a branch and make small changes on it.
12+
13+
4. Create a **draft PR**
14+
15+
5. Then make other changes and push to the remote branch you created. In this way, the maintainers will be able to provide early reviews and comments for your commits which will save time later on.
16+
17+
18+
6. Once the above steps are done, you can change the PR status from **draft to active**
19+
20+
21+
7. Once the PR is approved, make sure to update and sync your branch
22+
23+
8. Wait for the maintainers to merge your contribution
24+
25+
9. Congratulations! You made your first contribution to Leet Easy
26+
27+
<br>
28+
129
### Fixing a bug, or adding a new feature
230

331
This section generally defines how you can make code contribution. Please follow the below instructions to make code contributions.
432

5-
Code, PR, commit message format, etc convension I follow when I code. Please follow the links below to get details.
33+
Please follow the links given below to see the code, PR, commit message, etc. conventions which we follow.
634

7-
- [Git branch naming convension](BRANCH-NAMING.md)
35+
- [Git branch naming convention](BRANCH-NAMING.md)
836

937
- [Conventional Commits](https://www.conventionalcommits.org/) for commit messages, and [Commit message format](https://gist.github.com/digitaljhelms/3761873) for what to write
1038

1139
- [Linking a PR to an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
40+
41+
<br>
42+
43+
### Examples
44+
45+
#### Branch Names: `{branch_type}/{issue-tracker-id-}issue-one-liner`
46+
1. feature/2234-infinite-scroll
47+
2. documentation/3344-linux-installation
48+
3. test/2222-unit-tests
49+
50+
#### Commits
51+
1. [#1234] feature: Submit button added.
52+
2. [#1232] fix: Infinite scroll fixed
53+
3. [#333] test: Add unit tests for xyz feature
54+
55+
Keep contributing. We're eager to see your contributions!

leeteasy/__main__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import click
66
import schedule
77

8+
from leeteasy.constant import Constant
89
from leeteasy.services.notification_service import Notifier
910
from leeteasy.utils.validatiors import TimeValidator
1011

@@ -14,13 +15,13 @@
1415
'-d',
1516
'--difficulty',
1617
type=click.Choice(['Medium', 'Hard'], case_sensitive=False),
17-
help='Additional problem difficulty for notification.'
18+
help='Additional problem difficulty for notification.',
1819
)
1920
@click.option(
20-
"--sleep_duration",
21-
default=3600,
22-
type=click.IntRange(1, 3600, clamp=True),
23-
help='Sleep duration in seconds.'
21+
'--sleep_duration',
22+
default=Constant.DEFAULT_SLEEP,
23+
type=click.IntRange(1, Constant.DEFAULT_SLEEP, clamp=True),
24+
help='Sleep duration in seconds.',
2425
)
2526
@click.argument('time')
2627
def execute_start(time, difficulty, sleep_duration) -> None:
@@ -33,30 +34,32 @@ def execute_start(time, difficulty, sleep_duration) -> None:
3334
Notifier.target_difficulty.append(difficulty)
3435
schedule.every().day.at(time).do(Notifier.notify)
3536

36-
while True:
37+
while True: # NOQA: WPS457
3738
schedule.run_pending()
3839
clock.sleep(sleep_duration)
3940

4041

4142
@click.command('stop')
4243
def execute_stop() -> None:
43-
"""Stops leeteasy process"""
44+
"""Stop leeteasy process."""
4445
os.system('pkill -9 -f leeteasy')
4546

4647

4748
@click.group('leeteasy')
4849
def execute_root():
49-
"""v0.4.0 | supported version strings: 0.7.2"""
50-
pass
50+
"""Group child command."""
5151

5252

5353
execute_root.add_command(execute_start)
5454
execute_root.add_command(execute_stop)
5555

5656
if __name__ == '__main__':
5757
if platform != 'win32':
58-
import pwd
58+
import pwd # NOQA: WPS433
5959

60-
os.environ[
61-
'DBUS_SESSION_BUS_ADDRESS'] = f'unix:path=/run/user/{pwd.getpwuid(os.getuid()).pw_uid}/bus' # NOQA: E501
60+
bus_addr = 'unix:path=/run/user/{0}/bus'.format(
61+
pwd.getpwuid(os.getuid()).pw_uid,
62+
)
63+
64+
os.environ['DBUS_SESSION_BUS_ADDRESS'] = bus_addr
6265
execute_root()

leeteasy/constant.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ class Constant:
3434

3535
# http call retries
3636
HTTP_CALL_RETRIES = 3
37+
38+
# default sleep duration
39+
DEFAULT_SLEEP = 3600

leeteasy/models/challenge.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
from typing import List
1+
from typing import Dict, List, Optional
22

33

44
class Challenge:
55
"""Singleton Model class for daily challenge."""
66

77
title: str = ''
8-
raw_tags: List[dict] = None
8+
raw_tags: List[Dict[str, str]] = []
99
ac_rate: float = 0
10-
difficulty: str = None
11-
question_id: int = None
10+
difficulty: str = ''
11+
question_id: int = 0
1212
title_slug: str = ''
13-
date: str = None
13+
date: str = ''
1414

1515
def __new__(cls):
16-
if not hasattr(cls, 'instance'):
17-
cls.instance = super(Challenge, cls).__new__(cls)
16+
"""Override default class creation logic."""
17+
if not hasattr(cls, 'instance'): # NOQA : WPS421
18+
cls.instance = super(Challenge, cls).__new__(cls) # NOQA: WPS608
1819
return cls.instance
1920

2021
@property
2122
def problem_link(self) -> str:
22-
"""Returns the link of the problem."""
23+
"""Return the link of the problem."""
2324
return 'https://leetcode.com/problems/{0}/'.format(
2425
self.title_slug,
2526
)
2627

2728
@property
28-
def tags(self) -> List[str]:
29-
"""Returns the link of the problem."""
29+
def tags(self) -> List[Optional[str]]:
30+
"""Return the link of the problem."""
3031
tags = []
3132
for tag in self.raw_tags:
3233
tags.append(tag.get('name'))
3334
return tags
3435

3536
def __str__(self):
36-
"""Returns the string rep of the class."""
37-
return f"Title: {self.title}\nAcceptance Rate: {self.ac_rate}" \
38-
f"\nDifficulty: {self.difficulty}\n" + \
39-
f"id: {self.question_id}\nTags: {self.tags}"
37+
"""Return the string rep of the class."""
38+
return 'Title: {0}\nAcceptance: {1}\nDifficulty: {2}\nID: {3}\nTags: {4}\n'.format(
39+
self.title,
40+
self.ac_rate,
41+
self.difficulty,
42+
self.question_id,
43+
self.tags,
44+
)

leeteasy/services/notification_service.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from notifypy import Notify
44

5+
from leeteasy.models.challenge import Challenge
56
from leeteasy.services.request_handler import RequestHandler
67
from leeteasy.services.request_parser import RequestParser
78

@@ -11,11 +12,11 @@ class Notifier:
1112

1213
target_difficulty = ['Easy']
1314
app_name = 'LeetEasy'
14-
challenge = None
15+
challenge: Challenge
1516

1617
@classmethod
1718
def prepare_notification(cls):
18-
"""Prepares notification msg and triggers notification."""
19+
"""Prepare notification msg and triggers notification."""
1920
challenge_info = RequestHandler.get_challenge_info()
2021
cls.challenge = RequestParser.parse(challenge_info)
2122
if cls.challenge.difficulty in cls.target_difficulty:
@@ -27,14 +28,16 @@ def prepare_notification(cls):
2728
@classmethod
2829
def notify(cls):
2930
"""Send desktop notification."""
30-
app_name_with_subtitle = f'{cls.app_name} - Easy Problem Notification'
31+
app_name_with_subtitle = '{0} - Easy Problem Notification'.format(cls.app_name)
3132
icon_path = Path(__file__).parent.parent / 'assets/leetcoin.png'
3233
notification = Notify(
3334
default_notification_application_name=app_name_with_subtitle,
3435
default_notification_icon=icon_path,
3536
)
3637
notification.message = cls.prepare_notification()
37-
notification.title = f'{cls.app_name} - {cls.challenge.difficulty} ' \
38-
f'Problem Alert \U0001F514'
38+
notification.title = '{0} - {1} Problem Alert \U0001F514'.format(
39+
cls.app_name,
40+
cls.challenge.difficulty,
41+
)
3942
if notification.message:
4043
notification.send()

0 commit comments

Comments
 (0)