File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- /target
1+ target /
2+ venv /
23.direnv /
34.envrc
Original file line number Diff line number Diff line change 99 let
1010 system = "x86_64-linux" ;
1111 pkgs = import nixpkgs { inherit system ; } ;
12+ python = pkgs . python312 ;
13+ venv_dir = "./venv/" ;
1214 in
1315 {
1416 devShells . ${ system } . default = pkgs . mkShell {
1719 cargo
1820 clippy
1921 rust-analyzer
20- ( python312 . withPackages (
21- ps : with ps ; [
22- natsort
23- ]
24- ) )
22+ python . pkgs . venvShellHook
2523 ] ;
24+ venvDir = venv_dir ;
25+ postShellHook = ''
26+ SENTINEL="${ venv_dir } /.installed"
27+ REQUIREMENTS="requirements.txt"
28+
29+ if [ ! -f "$SENTINEL" ] || [ "$REQUIREMENTS" -nt "$SENTINEL" ]; then
30+ pip install --upgrade pip
31+ pip install -r "$REQUIREMENTS"
32+ touch "$SENTINEL"
33+ fi
34+ '' ;
2635 } ;
2736 } ;
2837}
Original file line number Diff line number Diff line change 1+ natsort == 8.4.0
2+ browser_cookie3 == 0.20.1
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import browser_cookie3 # type: ignore
4+ import os
5+ import re
6+
7+
8+ LEETCODE_URL = "https://leetcode.com"
9+
10+ CSRFTOKEN_KEY = "csrftoken"
11+ LEETCODE_SESSION_KEY = "LEETCODE_SESSION"
12+
13+
14+ CONFIG_LOCATION = "~/.leetcode/leetcode.toml"
15+ CONFIG_LOCATION = os .path .expanduser (CONFIG_LOCATION )
16+
17+ CSRF_CONFIG_REGEX = re .compile (r"^csrf = \".*\"$" , re .MULTILINE )
18+ SESSION_CONFIG_REGEX = re .compile (r"^session = \".*\"$" , re .MULTILINE )
19+
20+
21+ def main () -> None :
22+ cj = browser_cookie3 .chrome (domain_name = "leetcode.com" )
23+ cookies = {c .name : c .value for c in cj }
24+
25+ csrftoken = cookies [CSRFTOKEN_KEY ]
26+ leetcode_session = cookies [LEETCODE_SESSION_KEY ]
27+
28+ with open (CONFIG_LOCATION , "r" ) as f :
29+ content = f .read ()
30+
31+ content = CSRF_CONFIG_REGEX .sub (f'csrf = "{ csrftoken } "' , content )
32+ content = SESSION_CONFIG_REGEX .sub (f'session = "{ leetcode_session } "' , content )
33+
34+ with open (CONFIG_LOCATION , "w" ) as f :
35+ f .write (content )
36+
37+
38+ if __name__ == "__main__" :
39+ main ()
You can’t perform that action at this time.
0 commit comments