|
| 1 | +Fork form https://github.com/bonfy/leetcode |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +# leetcode_generate Usage |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Preparements: |
| 10 | + |
| 11 | +Use `selenium` and `PhantomJS` |
| 12 | + |
| 13 | +> I think it's not the best way. But I can't find way leetcode encrypt the csrftoken. |
| 14 | +> If anyone find the encrypt algoristhm, please pull request to me. And I can change the login to requests |
| 15 | +
|
| 16 | +Install `PhantomJS` please follow [PhantomJS official website](http://phantomjs.org/download.html) |
| 17 | + |
| 18 | +Mac Users can install `PhantomJS` by `Homebrew` |
| 19 | + |
| 20 | +``` cmd |
| 21 | +$ brew install phantomjs |
| 22 | +``` |
| 23 | + |
| 24 | +Install essential packages: `requests`, `pyquery`,`selenium` |
| 25 | +```cmd |
| 26 | +$ pyvenv venv # create virtual environment |
| 27 | +$ source venv/bin/activate |
| 28 | +$ pip3 install -r req.txt |
| 29 | +``` |
| 30 | + |
| 31 | +## Config: |
| 32 | + |
| 33 | +Edit your own username, password, language and repo in the **config.cfg** file |
| 34 | + |
| 35 | +``` |
| 36 | +[leetcode] |
| 37 | +
|
| 38 | +username = username |
| 39 | +password = password |
| 40 | +language = python |
| 41 | +repo = https://github.com/bonfy/leetcode |
| 42 | +``` |
| 43 | + |
| 44 | +## Run |
| 45 | + |
| 46 | +### Fully Download |
| 47 | +```cmd |
| 48 | +python3 leetcode_generate.py |
| 49 | +``` |
| 50 | +Usually you can always run fully download |
| 51 | + |
| 52 | +### Download by id |
| 53 | +``` |
| 54 | +python3 leetcode_generate.py 1 |
| 55 | +python3 leetcode_generate.py 1 10 100 |
| 56 | +``` |
| 57 | +You can only download the solution you want. |
| 58 | +Just add the id arguments behind (seperate by space) |
| 59 | + |
| 60 | + |
| 61 | +## Attention |
| 62 | +Python 3 have tested |
| 63 | + |
| 64 | +Python 2 maybe |
| 65 | + |
| 66 | +## Changelog |
| 67 | + |
| 68 | +- 2016-10-09 Download codes from Leetcode and generate Readme |
| 69 | +- 2016-11-25 Add multi language support |
| 70 | +- 2017-01-02 Fix the bug cause by Leetcode change website: `PHPSESSID` change to `LEETCODE_SESSION` |
| 71 | +- 2017-04-22 Fix the bug cause by Leetcode change website: csrftoken encrypt, submissions change from HTML to JSON |
0 commit comments