Skip to content

Commit 632d9b3

Browse files
committed
Added back csrf token env variable
1 parent 061d511 commit 632d9b3

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Diff for: .github/workflows/build-deck.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
&& sqlite3 collection.anki2 .dump
3131
env:
3232
LEETCODE_SESSION_ID: ${{ secrets.LEETCODE_SESSION_ID }}
33+
LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }}
3334
- name: Test build Anki Deck (non-default output file)
3435
run: >
3536
git clean -f -x -d
@@ -39,15 +40,18 @@ jobs:
3940
&& sqlite3 collection.anki2 .dump
4041
env:
4142
LEETCODE_SESSION_ID: ${{ secrets.LEETCODE_SESSION_ID }}
43+
LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }}
4244
- name: Test build Anki Deck with Amazon list id
4345
run: python generate.py --stop 10 --list-id 7p5x763
4446
env:
4547
LEETCODE_SESSION_ID: ${{ secrets.LEETCODE_SESSION_ID }}
48+
LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }}
4649
- name: Build Anki Deck
4750
run: python generate.py
4851
if: github.ref == 'refs/heads/master'
4952
env:
5053
LEETCODE_SESSION_ID: ${{ secrets.LEETCODE_SESSION_ID }}
54+
LEETCODE_CSRF_TOKEN: ${{ secrets.LEETCODE_CSRF_TOKEN }}
5155
- name: Create Release
5256
id: create_release
5357
uses: actions/create-release@v1

Diff for: README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,45 @@ I personally use it to track my grinding progress.
2727

2828
## How to run
2929
First download the source code
30-
```
30+
```sh
3131
git clone https://github.com/prius/leetcode-anki.git
3232
cd leetcode-anki
3333
```
3434

3535
After that initialize and activate python virtualenv somewhere
3636

3737
Linux/MacOS
38-
```
38+
```sh
3939
virtualenv -p python leetcode-anki
4040
. leetcode-anki/bin/activate
4141
```
4242

4343
Windows
44-
```
44+
```sh
4545
python -m venv leetcode-anki
4646
.\leetcode-anki\Scripts\activate.bat
4747
```
4848

49-
Then initialize session id variable. You can get it directly from your browser (if you're using chrome, cookies can be found here chrome://settings/cookies/detail?site=leetcode.com)
49+
Then initialize necessary environment variables. You can get it directly from your browser cookies (`csrftoken` and `LEETCODE_SESSION`)
5050

5151
Linux/Macos
52-
```
52+
```sh
53+
export LEETCODE_CSRF_TOKEN="xxx"
5354
export LEETCODE_SESSION_ID="yyy"
5455
```
5556

5657
Windows
57-
```
58+
```sh
59+
set LEETCODE_CSRF_TOKEN="xxx"
5860
set LEETCODE_SESSION_ID="yyy"
5961
```
6062

6163
And finally run for Linux/MacOS
62-
```
64+
```sh
6365
make generate
6466
```
6567
Or for Windows
66-
```
68+
```sh
6769
pip install -r requirements.txt
6870
python generate.py
6971
```

Diff for: leetcode_anki/helpers/leetcode.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _get_leetcode_api_client() -> leetcode.api.default_api.DefaultApi:
3535
configuration = leetcode.configuration.Configuration()
3636

3737
session_id = os.environ["LEETCODE_SESSION_ID"]
38-
csrf_token = leetcode.auth.get_csrf_cookie(session_id)
38+
csrf_token = os.environ["LEETCODE_CSRF_TOKEN"]
3939

4040
configuration.api_key["x-csrftoken"] = csrf_token
4141
configuration.api_key["csrftoken"] = csrf_token
@@ -166,7 +166,7 @@ def _get_problems_count(self) -> int:
166166
skip=0,
167167
filters=leetcode.models.graphql_query_problemset_question_list_variables_filter_input.GraphqlQueryProblemsetQuestionListVariablesFilterInput(
168168
tags=[],
169-
list_id=self._list_id
169+
list_id=self._list_id,
170170
# difficulty="MEDIUM",
171171
# status="NOT_STARTED",
172172
# list_id="7p5x763", # Top Amazon Questions

0 commit comments

Comments
 (0)