1212 loader = FileSystemLoader (template_dir ), autoescape = select_autoescape (["html" , "xml" ])
1313)
1414
15+ EXCEL_COLUMNS = [
16+ "ID" ,
17+ "Title" ,
18+ "Difficulty" ,
19+ "URL" ,
20+ "Date Attempted" ,
21+ "Tags" ,
22+ "Neetcode Video" ,
23+ "Neetcode Short" ,
24+ "Solution Code" ,
25+ "Solutions" ,
26+ "Companies" ,
27+ ]
28+
29+ DATE_COLUMN_INDEX = EXCEL_COLUMNS .index ("Date Attempted" )
30+ DIFFICULTY_COLUMN_INDEX = EXCEL_COLUMNS .index ("Difficulty" )
31+
1532
1633def format_solution_link (slug : str , solution_id : str ) -> str :
1734 """
18- format a link to the LeetCode solution with the given ID.
35+ Format a link to the LeetCode solution with the given ID.
1936
2037 Arguments
2138 ---------
@@ -36,13 +53,13 @@ def render_template(
3653 template_path : Optional [str ], template_name : Optional [str ], ** kwargs
3754) -> str :
3855 """
39- Render a template with the given context
56+ Render a template with the given context.
4057
4158 Arguments
4259 ---------
4360 template_path : Optional[str]
4461 Path to a custom template file. If None, use built-in templates.
45- template_name : str
62+ template_name : Optional[ str]
4663 Name of the built-in template to use if template_path is None.
4764 kwargs : dict
4865 Template context variables.
@@ -54,6 +71,7 @@ def render_template(
5471 """
5572 if not template_path and not template_name :
5673 raise ValueError ("Either template_path or template_name must be provided" )
74+
5775 if template_path :
5876 custom_dir = Path (template_path ).parent
5977 custom_file = Path (template_path ).name
@@ -63,7 +81,6 @@ def render_template(
6381 )
6482 template = custom_env .get_template (custom_file )
6583 else :
66- assert template_name is not None
6784 template = env .get_template (template_name )
6885
6986 kwargs ["solution_url" ] = format_solution_link
@@ -74,7 +91,7 @@ def format_anki(
7491 url : str , slug : str , data : dict , template_path : Optional [str ] = None
7592) -> str :
7693 """
77- formats an Anki problem using Jinja template
94+ Format an Anki problem using a Jinja template.
7895
7996 Arguments
8097 ---------
@@ -108,30 +125,9 @@ def format_anki(
108125 return rendered
109126
110127
111- def format_quizlet (url : str , slug : str , data : dict ):
112- """
113- formats a Quizlet problem for the given URL and data
114-
115- Arguments
116- ---------
117- url : str
118- The URL of the question to format a problem for.
119- slug : str
120- The slug of the question to format a problem for.
121- data : dict
122- The data of the question to format a problem for.
123-
124- Returns
125- -------
126- str
127- The Quizlet problem for the given URL and data.
128- """
129- pass
130-
131-
132128def format_excel (url : str , slug : str , data : dict ) -> List [Union [str , date ]]:
133129 """
134- formats an Excel problem for the given URL and data
130+ Format an Excel row for the given URL and data.
135131
136132 Arguments
137133 ---------
@@ -144,57 +140,42 @@ def format_excel(url: str, slug: str, data: dict) -> List[Union[str, date]]:
144140
145141 Returns
146142 -------
147- str
148- The Excel problem for the given URL and data. The problem
149- is formatted as a list of strings, where each string is a
150- column in the Excel file. This row will have the ordering:
151- [id, title, difficulty, url, date attempted, tags, video_url, short_url, solutions, companies]
143+ List[Union[str, date]]
144+ A list of cell values matching EXCEL_COLUMNS:
145+ [id, title, difficulty, url, date_attempted, tags,
146+ video_url, short_url, solution_code, solutions, companies]
152147 """
153- row = []
154- row .append (data ["id" ])
155- row .append (data ["title" ])
156- row .append (data ["difficulty" ])
157- row .append (get_url (url ))
158- row .append (date .today ())
159- row .append (", " .join ([tag ["name" ] for tag in data ["tags" ]]))
160- if str (data ["id" ]) in LEETCODE_TO_NEETCODE :
161- neetcode_data = LEETCODE_TO_NEETCODE [str (data ["id" ])]
162- # Add regular video URL
163- video_url = neetcode_data .get ("video" , {}).get ("url" , "" )
164- row .append (video_url )
165- # Add shorts URL in new column
166- short_url = neetcode_data .get ("short" , {}).get ("url" , "" )
167- row .append (short_url )
168- else :
169- row .append ("" ) # No regular video
170- row .append ("" ) # No short
171- row .append (data .get ("neetcode_solution" , "" ))
172- row .append (
148+ neetcode = LEETCODE_TO_NEETCODE .get (str (data ["id" ]), {})
149+
150+ return [
151+ data ["id" ],
152+ data ["title" ],
153+ data ["difficulty" ],
154+ get_url (url ),
155+ date .today (),
156+ ", " .join (tag ["name" ] for tag in data ["tags" ]),
157+ neetcode .get ("video" , {}).get ("url" , "" ),
158+ neetcode .get ("short" , {}).get ("url" , "" ),
159+ data .get ("neetcode_solution" , "" ),
173160 "\n " .join (
174- [
175- format_solution_link (slug , solution ["id" ])
176- for solution in data ["solutions" ]
177- ]
178- )
179- )
180- if data .get ("companies" ):
181- row .append (", " .join ([company ["name" ] for company in data ["companies" ]]))
182- else :
183- row .append ("" )
184- return row
161+ format_solution_link (slug , solution ["id" ]) for solution in data ["solutions" ]
162+ ),
163+ ", " .join (company ["name" ] for company in (data .get ("companies" ) or [])),
164+ ]
185165
186166
187167FORMAT_MAP = {
188168 "anki" : format_anki ,
189- "quizlet" : format_quizlet ,
190169 "excel" : format_excel ,
191170}
192171
193172__all__ = [
194173 "format_solution_link" ,
195174 "format_anki" ,
196- "format_quizlet" ,
197175 "format_excel" ,
198176 "FORMAT_MAP" ,
199177 "render_template" ,
178+ "EXCEL_COLUMNS" ,
179+ "DATE_COLUMN_INDEX" ,
180+ "DIFFICULTY_COLUMN_INDEX" ,
200181]
0 commit comments