Skip to content

Commit 1f00abe

Browse files
Apply consistent formatting and add dotenv dependency
Introduced formatting improvements across multiple files for better readability, such as consistent line breaks and indentation. Added `python-dotenv` to requirements and loaded environment variables in `SessionManager.py` to support `.env` file configurations.
1 parent ef639a9 commit 1f00abe

16 files changed

+127
-24
lines changed

PracticeFactory.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"hard": "Hard",
1111
}
1212

13+
1314
class PracticeMode:
1415
def handle(self, args):
1516
raise NotImplementedError("This method should be implemented by subclasses.")
1617

18+
1719
class RandomProblemMode(PracticeMode):
1820
def handle(self, args):
1921
problem = get_random_problem(args["difficulties"])
@@ -26,6 +28,7 @@ def handle(self, args):
2628
# Open in browser if flag is set
2729
if args["open_in_browser"]:
2830
import webbrowser
31+
2932
webbrowser.open(f"https://leetcode.com/problems/{problem['slug']}")
3033

3134
handler = SolutionHandler(
@@ -37,12 +40,15 @@ def handle(self, args):
3740
)
3841
handler.solve()
3942

43+
4044
class DailyChallengeMode(PracticeMode):
4145
def handle(self, args):
4246
try:
4347
daily_challenge = fetch_daily_challenge()
4448

45-
difficulty_label = difficulty_map[daily_challenge["question"]["difficulty"].lower()]
49+
difficulty_label = difficulty_map[
50+
daily_challenge["question"]["difficulty"].lower()
51+
]
4652

4753
# Log daily challenge details
4854
log("🎯 Daily Coding Challenge:", LogLevel.INFO)
@@ -53,6 +59,7 @@ def handle(self, args):
5359

5460
if args["open_in_browser"]:
5561
import webbrowser
62+
5663
webbrowser.open(f"https://leetcode.com{daily_challenge['link']}")
5764

5865
handler = SolutionHandler(
@@ -66,6 +73,7 @@ def handle(self, args):
6673
except Exception as e:
6774
log(f"Failed to fetch daily challenge: {str(e)}", LogLevel.ERROR)
6875

76+
6977
class CustomPracticeMode(PracticeMode):
7078
def handle(self, args):
7179
problems = args["problems"]
@@ -85,6 +93,7 @@ def handle(self, args):
8593

8694
if args["open_in_browser"]:
8795
import webbrowser
96+
8897
webbrowser.open(f"https://leetcode.com/problems/{problem['slug']}")
8998

9099
handler = SolutionHandler(
@@ -98,6 +107,7 @@ def handle(self, args):
98107
except Exception as e:
99108
log(f"Failed to process problem '{slug}': {str(e)}", LogLevel.ERROR)
100109

110+
101111
class PracticeModeFactory:
102112
@staticmethod
103113
def get_mode(selection_mode: str) -> PracticeMode:

handlers/SolutionHandler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ def _create_file(self, language):
3535

3636
def _setup_watcher(self, file_path, language, time_limit):
3737
setup_file_watcher(file_path, self.problem, language, time_limit)
38-
log(f"⏳ You have {time_limit} minutes to solve the problem. Good luck!", LogLevel.INFO)
38+
log(
39+
f"⏳ You have {time_limit} minutes to solve the problem. Good luck!",
40+
LogLevel.INFO,
41+
)
3942
log(f"✨ Difficulty Level: {self.difficulty}", LogLevel.INFO)

handlers/file_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
language_to_extension = {
4-
"python3": "py",
4+
"python": "py",
55
"javascript": "js",
66
"java": "java",
77
"c++": "cpp",
@@ -14,6 +14,7 @@
1414

1515
available_languages = list(language_to_extension.keys())
1616

17+
1718
def create_solution_file(problem_slug: str, language: str) -> str:
1819
"""
1920
Create a solution file for the specified problem and language.

lib/fetch_daily_challenge.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
from typing import Dict, Any
44

5+
56
def fetch_daily_challenge() -> Dict[str, Any]:
67
"""
78
Fetch details for the LeetCode Daily Coding Challenge.
@@ -44,7 +45,11 @@ def fetch_daily_challenge() -> Dict[str, Any]:
4445
"Content-Type": "application/json",
4546
"Cookie": f"LEETCODE_SESSION={leetcode_session}",
4647
}
47-
response = requests.post(url, headers=headers, json={"operationName": "questionOfToday", "variables": {}, "query": query})
48+
response = requests.post(
49+
url,
50+
headers=headers,
51+
json={"operationName": "questionOfToday", "variables": {}, "query": query},
52+
)
4853

4954
if not response.ok:
5055
raise Exception(f"❌ Failed to fetch daily challenge: {response.reason}")

lib/fetch_problem.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
from typing import Dict, Any
44

5+
56
def fetch_problem(problem_slug: str) -> Dict[str, Any]:
67
"""
78
Fetch problem details from LeetCode.
@@ -37,7 +38,11 @@ def fetch_problem(problem_slug: str) -> Dict[str, Any]:
3738
response = requests.post(
3839
url,
3940
headers=headers,
40-
json={"operationName": "getQuestionDetails", "variables": {"titleSlug": problem_slug}, "query": query},
41+
json={
42+
"operationName": "getQuestionDetails",
43+
"variables": {"titleSlug": problem_slug},
44+
"query": query,
45+
},
4146
)
4247

4348
if not response.ok:

lib/fetch_problems.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
# TODO: Need to verify how `fetchProblems` functions with multiple difficulty levels.
99
# TODO: Need to add tests to tests/.
1010

11-
def fetch_problems(limit: int = 50, skip: int = 0, difficulties: List[str] = None) -> List[Dict[str, Any]]:
11+
12+
def fetch_problems(
13+
limit: int = 50, skip: int = 0, difficulties: List[str] = None
14+
) -> List[Dict[str, Any]]:
1215
"""
1316
Fetch a list of problems from LeetCode.
1417
:param limit: Number of problems to fetch.
@@ -59,7 +62,15 @@ def fetch_problems(limit: int = 50, skip: int = 0, difficulties: List[str] = Non
5962
"skip": skip,
6063
"filters": {"difficulty": difficulties or []},
6164
}
62-
response = requests.post(url, headers=headers, json={"operationName": "problemsetQuestionList", "variables": variables, "query": query})
65+
response = requests.post(
66+
url,
67+
headers=headers,
68+
json={
69+
"operationName": "problemsetQuestionList",
70+
"variables": variables,
71+
"query": query,
72+
},
73+
)
6374

6475
if not response.ok:
6576
raise Exception(f"❌ Failed to fetch problems: {response.reason}")
@@ -72,7 +83,10 @@ def fetch_problems(limit: int = 50, skip: int = 0, difficulties: List[str] = Non
7283

7384
return questions
7485

75-
def get_random_problem(difficulties: Optional[List[str]] = None) -> Optional[Dict[str, Any]]:
86+
87+
def get_random_problem(
88+
difficulties: Optional[List[str]] = None,
89+
) -> Optional[Dict[str, Any]]:
7690
"""
7791
Get a random problem from LeetCode.
7892
:param difficulties: Difficulty levels of the problems (e.g., "Easy", "Medium", "Hard").

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ def main():
2121
log(f"Error: {str(e)}", LogLevel.ERROR)
2222
exit(1)
2323

24+
2425
if __name__ == "__main__":
2526
main()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mypy-extensions==1.0.0
77
packaging==24.2
88
pathspec==0.12.1
99
platformdirs==4.3.6
10+
python-dotenv==1.0.1
1011
requests==2.32.3
1112
tomli==2.2.1
1213
typing_extensions==4.12.2

score.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
score = 0
99
streak = 0
1010

11+
1112
def load_problem_count():
1213
try:
1314
if not os.path.exists(problem_count_file_path):
@@ -21,6 +22,7 @@ def load_problem_count():
2122
log(f"Failed to load problem count: {str(e)}", LogLevel.ERROR)
2223
return default_problem_count
2324

25+
2426
def update_problem_count(difficulty, count):
2527
try:
2628
problem_count = load_problem_count()
@@ -42,6 +44,7 @@ def update_problem_count(difficulty, count):
4244
except Exception as e:
4345
log(f"Failed to update problem count: {str(e)}", LogLevel.ERROR)
4446

47+
4548
def update_score(difficulty, completed_in_time):
4649
global score, streak
4750
base_points = {"easy": 10, "medium": 20, "hard": 30}
@@ -56,7 +59,10 @@ def update_score(difficulty, completed_in_time):
5659
current_count = problem_count[difficulty]
5760

5861
if current_count <= 0:
59-
log(f"No more problems available for difficulty '{difficulty}'.", LogLevel.WARN)
62+
log(
63+
f"No more problems available for difficulty '{difficulty}'.",
64+
LogLevel.WARN,
65+
)
6066
return
6167

6268
rarity_factor = 50 / current_count if current_count else 1
@@ -68,6 +74,12 @@ def update_score(difficulty, completed_in_time):
6874

6975
update_problem_count(difficulty, current_count - 1)
7076

71-
log(f"🏆 Score: {score}, 🔥 Streak: {streak} (+{points} points), ✨ Difficulty: {difficulty}", LogLevel.INFO)
77+
log(
78+
f"🏆 Score: {score}, 🔥 Streak: {streak} (+{points} points), ✨ Difficulty: {difficulty}",
79+
LogLevel.INFO,
80+
)
7281
except Exception as e:
73-
log(f"Error updating score for difficulty '{difficulty}': {str(e)}", LogLevel.ERROR)
82+
log(
83+
f"Error updating score for difficulty '{difficulty}': {str(e)}",
84+
LogLevel.ERROR,
85+
)

services/CommandParser.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
import argparse
22

3+
34
def parse():
45
parser = argparse.ArgumentParser(description="🦑 SquidLeet CLI Tool")
56
parser.add_argument("--leetcode-session", type=str, help="LeetCode session token")
6-
parser.add_argument("--practice-mode", type=str, choices=["custom", "random", "study-plan", "daily"], default="random", help="Practice mode")
7-
parser.add_argument("--difficulties", type=str, help="Comma-separated difficulty levels (easy, medium, hard)", default="easy,medium,hard")
8-
parser.add_argument("--problems", type=str, help="Comma-separated problem slugs (e.g., 'two-sum,fizz-buzz')")
9-
parser.add_argument("--language", type=str, help="Programming language to use", default="python")
10-
parser.add_argument("--time-limit", type=int, help="Time limit for practice in minutes", default=45)
11-
parser.add_argument("--editor", type=str, help="Editor to use for files", default="default")
12-
parser.add_argument("--open-in-browser", action="store_true", help="Open the problem in a browser")
7+
parser.add_argument(
8+
"--practice-mode",
9+
type=str,
10+
choices=["custom", "random", "study-plan", "daily"],
11+
default="random",
12+
help="Practice mode",
13+
)
14+
parser.add_argument(
15+
"--difficulties",
16+
type=str,
17+
help="Comma-separated difficulty levels (easy, medium, hard)",
18+
default="easy,medium,hard",
19+
)
20+
parser.add_argument(
21+
"--problems",
22+
type=str,
23+
help="Comma-separated problem slugs (e.g., 'two-sum,fizz-buzz')",
24+
)
25+
parser.add_argument(
26+
"--language", type=str, help="Programming language to use", default="python"
27+
)
28+
parser.add_argument(
29+
"--time-limit", type=int, help="Time limit for practice in minutes", default=45
30+
)
31+
parser.add_argument(
32+
"--editor", type=str, help="Editor to use for files", default="default"
33+
)
34+
parser.add_argument(
35+
"--open-in-browser", action="store_true", help="Open the problem in a browser"
36+
)
1337

1438
return vars(parser.parse_args())

0 commit comments

Comments
 (0)