Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frequency to cards #4

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async def _get_problem_data(self, problem_slug: str) -> Dict[str, str]:
query="""
query getQuestionDetail($titleSlug: String!) {
question(titleSlug: $titleSlug) {
freqBar
questionId
questionFrontendId
boundTopicId
Expand Down Expand Up @@ -222,6 +223,10 @@ async def tags(self, problem_slug: str) -> List[str]:
data = await self._get_problem_data(problem_slug)
return list(map(lambda x: x.slug, data.topic_tags))

async def freq_bar(self, problem_slug: str) -> float:
data = await self._get_problem_data(problem_slug)
return data.freq_bar or 0


class LeetcodeNote(genanki.Note):
@property
Expand Down Expand Up @@ -286,8 +291,11 @@ async def generate_anki_note(
* 100
)
),
str(await leetcode_data.freq_bar(leetcode_task_handle)),
],
tags=await leetcode_data.tags(leetcode_task_handle),
# FIXME: sort field doesn't work doesn't work
sort_field=str(await leetcode_data.freq_bar(leetcode_task_handle)).zfill(3),
)


Expand All @@ -308,6 +316,7 @@ async def generate(start: int, stop: int) -> None:
{"name": "SubmissionsTotal"},
{"name": "SubmissionsAccepted"},
{"name": "SumissionAcceptRate"},
{"name": "Frequency"},
# TODO: add hints
],
templates=[
Expand All @@ -322,6 +331,11 @@ async def generate(start: int, stop: int) -> None:
({{SumissionAcceptRate}}%)
<br/>
<b>Topic:</b> {{Topic}}<br/>
<b>Frequency:</b>
<progress value="{{Frequency}}" max="100">
{{Frequency}}%
</progress>
<br/>
<b>URL:</b>
<a href='https://leetcode.com/problems/{{Slug}}/'>
https://leetcode.com/problems/{{Slug}}/
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python-leetcode==1.0.9
python-leetcode==1.0.10
setuptools==57.5.0
diskcache
genanki
Expand Down