Created
August 11, 2022 05:39
-
-
Save ImSingee/ca50e8acf1562ba135f314263c50bbd5 to your computer and use it in GitHub Desktop.
Revisions
-
ImSingee created this gist
Aug 11, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #!/opt/bin/python3 # pip install markdownify import os import requests question_id = os.environ.get('KMVAR_LeetCodeID', 'add-two-numbers').strip() cookies={ "LEETCODE_SESSION": '' } def get_csrf_cookie() -> str: response = requests.get( "https://leetcode.com/", cookies=cookies, ) return response.cookies["csrftoken"] HEADERS = { 'x-csrftoken': get_csrf_cookie(), } def get_leetcode_question_title(title_slug: str): query = '''query questionData($titleSlug: String!) { question(titleSlug: $titleSlug) { questionId questionFrontendId translatedTitle __typename } } ''' request_body = { 'operationName': "questionData", 'query': query, 'variables': { 'titleSlug': title_slug, } } response = requests.post('https://leetcode-cn.com/graphql/', headers=HEADERS, cookies=cookies, json=request_body) return response.json()['data']['question']['translatedTitle'] print(get_leetcode_question_title(question_id).strip())