File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,18 @@ def __init__(self):
1717 exist_ok = True ,
1818 )
1919
20+ @staticmethod
21+ def get_solution_filename (language : str ) -> str :
22+ mapping = {
23+ "python3" : "solution.py" ,
24+ "java" : "Solution.java" ,
25+ "cpp" : "solution.cpp" ,
26+ "c" : "solution.c" ,
27+ "javascript" : "solution.js" ,
28+ }
29+
30+ return mapping .get (language , "solution.txt" )
31+
2032 @staticmethod
2133 def _format_folder_name (question_id : str , slug : str ) -> str :
2234 """
@@ -54,4 +66,23 @@ def create_problem_directory(self, detail) -> Path:
5466 exist_ok = True ,
5567 )
5668
57- return problem_dir
69+ return problem_dir
70+
71+
72+ def save_solution (self , detail ) -> Path :
73+ """
74+ Save the source code into the appropriate solution file.
75+ """
76+
77+ filename = self .get_solution_filename (detail .language )
78+
79+ problem_dir = self .create_problem_directory (detail )
80+
81+ solution_file = problem_dir / filename
82+
83+ solution_file .write_text (
84+ detail .code ,
85+ encoding = "utf-8" ,
86+ )
87+
88+ return solution_file
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
13+ from leetcode .downloader import SubmissionDownloader
1414
1515
1616console = Console ()
@@ -140,9 +140,11 @@ def main():
140140
141141 downloader = SubmissionDownloader ()
142142
143- folder = downloader .create_problem_directory (detail )
143+ solution_path = downloader .save_solution (detail )
144144
145- console .print (f"\n [green]Directory created:[/green] { folder } " )
145+ console .print (
146+ f"\n [bold green]Solution saved:[/bold green]\n { solution_path } "
147+ )
146148
147149if __name__ == "__main__" :
148150 main ()
You can’t perform that action at this time.
0 commit comments