Skip to content

Commit 5143a11

Browse files
committed
Add frequency to cards
1 parent 4646923 commit 5143a11

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

generate.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ async def _get_problem_data(self, problem_slug: str) -> Dict[str, str]:
8080
query="""
8181
query getQuestionDetail($titleSlug: String!) {
8282
question(titleSlug: $titleSlug) {
83+
frequency
8384
questionId
8485
questionFrontendId
8586
boundTopicId
@@ -233,22 +234,28 @@ def get_leetcode_api_client() -> leetcode.DefaultApi:
233234
return api_instance
234235

235236

236-
def get_leetcode_task_handles() -> Iterator[Tuple[str, str, str]]:
237+
def get_leetcode_task_handles() -> Iterator[Tuple[str, str, str, str]]:
237238
api_instance = get_leetcode_api_client()
238239

239240
for topic in ["algorithms", "database", "shell", "concurrency"]:
240241
api_response = api_instance.api_problems_topic_get(topic=topic)
241242
for stat_status_pair in api_response.stat_status_pairs:
242243
stat = stat_status_pair.stat
243244

244-
yield (topic, stat.question__title, stat.question__title_slug)
245+
yield (
246+
topic,
247+
stat.question__title,
248+
stat.question__title_slug,
249+
stat_status_pair.frequency,
250+
)
245251

246252

247253
async def generate_anki_note(
248254
leetcode_data: LeetcodeData,
249255
leetcode_model: genanki.Model,
250256
leetcode_task_handle: str,
251257
leetcode_task_title: str,
258+
leetcode_task_frequency: str,
252259
topic: str,
253260
) -> LeetcodeNote:
254261
return LeetcodeNote(
@@ -272,6 +279,7 @@ async def generate_anki_note(
272279
* 100
273280
)
274281
),
282+
str(leetcode_task_frequency),
275283
],
276284
tags=await leetcode_data.tags(leetcode_task_handle),
277285
)
@@ -294,6 +302,7 @@ async def generate(start: int, stop: int) -> None:
294302
{"name": "SubmissionsTotal"},
295303
{"name": "SubmissionsAccepted"},
296304
{"name": "SumissionAcceptRate"},
305+
{"name": "Frequency"},
297306
# TODO: add hints
298307
],
299308
templates=[
@@ -308,6 +317,11 @@ async def generate(start: int, stop: int) -> None:
308317
({{SumissionAcceptRate}}%)
309318
<br/>
310319
<b>Topic:</b> {{Topic}}<br/>
320+
<b>Frequency:</b>
321+
<progress value="{{Frequency}}" max="100">
322+
{{Frequency}}%
323+
</progress>
324+
<br/>
311325
<b>URL:</b>
312326
<a href='https://leetcode.com/problems/{{Slug}}/'>
313327
https://leetcode.com/problems/{{Slug}}/
@@ -338,15 +352,19 @@ async def generate(start: int, stop: int) -> None:
338352

339353
note_generators: List[Coroutine[Any, Any, LeetcodeNote]] = []
340354

341-
for topic, leetcode_task_title, leetcode_task_handle in list(
342-
get_leetcode_task_handles()
343-
)[start:stop]:
355+
for (
356+
topic,
357+
leetcode_task_title,
358+
leetcode_task_handle,
359+
leetcode_task_frequency,
360+
) in list(get_leetcode_task_handles())[start:stop]:
344361
note_generators.append(
345362
generate_anki_note(
346363
leetcode_data,
347364
leetcode_model,
348365
leetcode_task_handle,
349366
leetcode_task_title,
367+
leetcode_task_frequency,
350368
topic,
351369
)
352370
)

0 commit comments

Comments
 (0)