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 #3

Closed
gh4n opened this issue Oct 14, 2021 · 7 comments · Fixed by #4
Closed

Add frequency #3

gh4n opened this issue Oct 14, 2021 · 7 comments · Fixed by #4

Comments

@gh4n
Copy link

gh4n commented Oct 14, 2021

Hey @prius would it be possible to get the frequency of a problem as a tag in anki? This would make it a lot easier to prioritise canonical problems.

Thanks I really love this tool!

@fspv
Copy link
Owner

fspv commented Oct 14, 2021

Hello @gh4n

Unfortunately looks like it is not possible. Leetcode API returns 0.0 for all the questions.

Check this one for example https://leetcode.com/problems/perfect-squares/

It returns zero frequency:

{'difficulty': {'level': 2},                                                                                                                                                                                                                 
 'frequency': 0.0,                                                                                                                                                                                                                           
 'is_favor': False,                                                                                                                                                                                                                          
 'paid_only': False,                                                                                                                                                                                                                         
 'progress': 0.0,                                                                                                                                                                                                                            
 'stat': {'frontend_question_id': 279,                                                                                                                                                                                                       
          'is_new_question': False,                                                                                                                                                                                                          
          'question__article__has_video_solution': 'False',                                                                                                                                                                                  
          'question__article__live': 'True',                                                                                                                                                                                                 
          'question__article__slug': 'perfect-squares',                                                                                                                                                                                      
          'question__hide': False,                                                                                                                                                                                                           
          'question__title': 'Perfect Squares',                                                                                                                                                                                              
          'question__title_slug': 'perfect-squares',                                                                                                                                                                                         
          'question_id': 279,                                                                                                                                                                                                                
          'total_acs': 443520,                                                                                                                                                                                                               
          'total_submitted': 878622},                                                                                                                                                                                                        
 'status': None}   

Even though the real frequency is 35%

Selection_324

I'll check if it is possible to fetch this infromation via graphql API.

@fspv
Copy link
Owner

fspv commented Oct 14, 2021

Graphql returns zero as well.

send: b'{"query": "\\n            query getQuestionDetail($titleSlug: String!) {\\n              question(titleSlug: $titleSlug) {\\n                frequency\\n                topicTags {\\n                  name\\n                  slug\\n                }\\n              }\\n            }\\n        ", "variables": {"titleSlug": "two-sum"}, "operationName": "getQuestionDetail"}'
reply: 'HTTP/1.1 200 OK\r\n'
<...>
2021-10-14 15:47:25,827 DEBUG https://leetcode.com:443 "POST /graphql HTTP/1.1" 200 127
2021-10-14 15:47:25,828 DEBUG response body: {"data":{"question":{"frequency":0.0,"topicTags":[{"name":"Array","slug":"array"},{"name":"Hash Table","slug":"hash-table"}]}}}

Looks like this information is not available publicitly. Let me know if you find other ways to acquire it. The code change to add it to the card is simple once I have the information. Here is a PR for that #4 (so I can reuse it later in case it is needed)

@fspv fspv closed this as completed Oct 14, 2021
@fspv
Copy link
Owner

fspv commented Oct 16, 2021

Found out that GraphQL request problemsetQuestionList returns correct frequency. Will try again later.

@fspv fspv reopened this Oct 16, 2021
@gh4n
Copy link
Author

gh4n commented Oct 17, 2021

Thanks if I get a chance I’ll have a look too!

@fspv
Copy link
Owner

fspv commented Oct 22, 2021

One more observation. The frequency field is null when you remove csrf cookie from the request. Need to check if the propagation of the cookie works correctly within the leetcode client.

@fspv
Copy link
Owner

fspv commented Oct 22, 2021

Okay. It's confirmed. LC client with expired csrf cookies returns null frequency. Running it with up to date cookie returns an actual value.

@fspv
Copy link
Owner

fspv commented Oct 22, 2021

Frequency added #4

The sorting by this field doesn't work though. I've created a separate issue for that #10

@fspv fspv closed this as completed Oct 22, 2021
@fspv fspv linked a pull request Oct 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants