File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ from config .settings import Config
4+
5+
6+ class SubmissionDownloader :
7+ """
8+ Handles downloading and storing LeetCode submissions locally.
9+ """
10+
11+ def __init__ (self ):
12+ self .solutions_dir = Config .STORAGE_DIR / "solutions"
13+
14+ # Create storage/solutions if it doesn't exist
15+ self .solutions_dir .mkdir (
16+ parents = True ,
17+ exist_ok = True ,
18+ )
19+
20+ @staticmethod
21+ def _format_folder_name (question_id : str , slug : str ) -> str :
22+ """
23+ Convert:
24+ 295
25+ find-median-from-data-stream
26+
27+ Into:
28+ 0295_Find_Median_from_Data_Stream
29+ """
30+
31+ problem_number = str (question_id ).zfill (4 )
32+
33+ title = "_" .join (
34+ word .capitalize ()
35+ for word in slug .split ("-" )
36+ )
37+
38+ return f"{ problem_number } _{ title } "
39+
40+ def create_problem_directory (self , detail ) -> Path :
41+ """
42+ Create the directory for a problem if it doesn't already exist.
43+ """
44+
45+ folder_name = self ._format_folder_name (
46+ detail .question_id ,
47+ detail .title_slug ,
48+ )
49+
50+ problem_dir = self .solutions_dir / folder_name
51+
52+ problem_dir .mkdir (
53+ parents = True ,
54+ exist_ok = True ,
55+ )
56+
57+ return problem_dir
Original file line number Diff line number Diff line change 1010from leetcode .api import LeetCodeAPI
1111from config .settings import Config
1212
13+ from leetcode .downloader import SubmissionDownloader
14+
1315
1416console = Console ()
1517
@@ -133,5 +135,14 @@ def main():
133135 20 : "Compile Error" ,
134136}
135137 console .print (f"Status : { STATUS_MAP .get (detail .status_code , 'Unknown' )} " )
138+
139+ detail = api .get_submission_detail (submissions [0 ].id )
140+
141+ downloader = SubmissionDownloader ()
142+
143+ folder = downloader .create_problem_directory (detail )
144+
145+ console .print (f"\n [green]Directory created:[/green] { folder } " )
146+
136147if __name__ == "__main__" :
137148 main ()
You can’t perform that action at this time.
0 commit comments