leetcoder 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Dockerfile +1 -2
- data/README.md +73 -6
- data/leetcoder.yml +35 -0
- data/lib/leetcoder/leetcoder/client.rb +17 -0
- data/lib/leetcoder/leetcoder/download.rb +6 -2
- data/lib/leetcoder/leetcoder/helpers/logger.rb +6 -2
- data/lib/leetcoder/leetcoder/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed539ebbfa265645b33930912bbc686284cf9dd7a00cae912331b6a034eb634
|
4
|
+
data.tar.gz: d5e94973e36895f844fb62fb3074acd6866e61190bb4bcf8aae88839990053a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b998b4714b7a431f1dce223d3ba2f0d65eabb7e6a32cafdd616b749c6c55fa1d056d375bc8868a35db1f656d27525460e0ace812c7fa58e176b41bec76e703
|
7
|
+
data.tar.gz: 91a4b1341c86870c4bf08191b50e3ef5d2f38e4c51641763771a4e5ef72514fa4cf84de7dd269877f0a44e9a325fb13463ed954f1bb10c21f1811d497b804f59
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,52 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<img src="./spec/cassettes/leetcoder.png" alt="leetcoder"/>
|
3
|
+
</p>
|
2
4
|
|
3
|
-
|
4
|
-
<img src="/spec/cassettes/leet_coder.png" alt="leetcoder" float="right" height="300px"/>
|
5
|
+
A Ruby [LeetCode](https://www.leetcode.com) Client to help you download all your accepted leetcode submissions with problem description. LeetCode cookie is used for authentication.
|
5
6
|
|
6
|
-
|
7
|
+
- [Leetcoder](#)
|
8
|
+
- [Screenshot](#screenshot)
|
9
|
+
- [Requirements](#requirements)
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Usage](#usage)
|
12
|
+
- [Run Through Docker](#run-through-docker)
|
13
|
+
- [Run Through Github Action](#run-through-github-action)
|
14
|
+
- [Author](#author)
|
15
|
+
|
16
|
+
## Screenshot
|
17
|
+
|
18
|
+

|
19
|
+
|
20
|
+
## Requirements
|
21
|
+
- Ruby 3.1.1
|
22
|
+
- Desire to automate the boring stuff
|
7
23
|
|
8
24
|
## Installation
|
9
25
|
|
10
|
-
```
|
26
|
+
```bash
|
11
27
|
gem install leetcoder
|
12
28
|
```
|
13
29
|
|
14
30
|
## Usage
|
15
31
|
|
32
|
+
After installing the gem, follow these steps:
|
33
|
+
|
34
|
+
- Sign in to [leetcode.com](www.leetcode.com) from any browser
|
35
|
+
- Copy the `cookie` value of a leetcode request using the browser network tab
|
36
|
+
|
37
|
+

|
38
|
+
|
39
|
+
- Save your cookie by running `leetcoder --cookie` from terminal
|
40
|
+
- Run `leetcoder --download` to start downloading.
|
41
|
+
|
42
|
+
```bash
|
43
|
+
leetcoder --cookie # prompt you to save the leetcode cookie
|
44
|
+
leetcoder --download all --folder ./ # download all accepted submissions in current folder
|
16
45
|
```
|
46
|
+
|
47
|
+
```bash
|
48
|
+
> leetcoder --help
|
49
|
+
|
17
50
|
Usage: leetcoder [command]
|
18
51
|
|
19
52
|
* indicates default value
|
@@ -26,6 +59,40 @@ commands:
|
|
26
59
|
-h, --help Show available commands
|
27
60
|
```
|
28
61
|
|
29
|
-
##
|
62
|
+
## Run through Github Action
|
63
|
+
|
64
|
+
Create a new repository in github and set your leetcode cookie under `Repository Secrets` with name `LEETCODE_COOKIE` in
|
65
|
+
|
66
|
+
```text
|
67
|
+
https://github.com/<username>/<repo_name>/settings/secrets/actions
|
68
|
+
```
|
69
|
+
|
70
|
+
Then, Download and commit this [leetcoder.yml](./leetcoder.yml) file inside `.github/wrokflows/` folder in your repo.
|
71
|
+
|
72
|
+
This will automatically download and commit the downloaded submissions every week.
|
73
|
+
You can customize the frequency using the cron syntax inside the yml file.
|
74
|
+
|
75
|
+
This is the most convenient and recommended way to backup your submissions using the app.
|
76
|
+
|
77
|
+
## Run through Docker
|
78
|
+
|
79
|
+
If you don't have ruby setup locally, you can run the app through docker.
|
80
|
+
|
81
|
+
First, open terminal and cd to the directory where you want to download the submissions.
|
82
|
+
|
83
|
+
Then run,
|
84
|
+
|
85
|
+
```bash
|
86
|
+
docker run -it -v `pwd`:`pwd` -w `pwd` imamrb/leetcoder:latest
|
87
|
+
```
|
88
|
+
|
89
|
+
This will run the [leetcoder docker image](https://hub.docker.com/repository/docker/imamrb/leetcoder) and mount your current directory to container working directory. You can now continue using the app from here.
|
90
|
+
|
91
|
+
The downloaded submissions will be saved to your current directory.
|
92
|
+
|
93
|
+
Caveat: You will need to provide the leetcode cookie every time since the stored configuration will be lost when you exit from the container.
|
94
|
+
|
95
|
+
## Author
|
96
|
+
|
30
97
|
Imam Hossain <br>
|
31
98
|
Email: imam.swe@gmail.com
|
data/leetcoder.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
name: leetcoder auto download
|
2
|
+
on:
|
3
|
+
schedule:
|
4
|
+
- cron: "0 0 * * *"
|
5
|
+
workflow_dispatch:
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
jobs:
|
10
|
+
leetcoder-download:
|
11
|
+
runs-on: leetcoder:latest
|
12
|
+
env:
|
13
|
+
LEETCODE_COOKIE: ${{ secrets.LEETCODE_COOKIE }}
|
14
|
+
DOWNLOAD_FOLDER: './'
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 3.1.1
|
22
|
+
bundler-cache: true
|
23
|
+
|
24
|
+
- name: Install leetcoder
|
25
|
+
run: gem install leetcoder
|
26
|
+
|
27
|
+
- name: Download Submissions
|
28
|
+
run: leetcode -d all -f $DOWNLOAD_FOLDER
|
29
|
+
|
30
|
+
- name: Commit changes
|
31
|
+
uses: stefanzweifel/git-auto-commit-action@v4
|
32
|
+
with:
|
33
|
+
commit_message: 'leetcoder: updated leetcode submissions'
|
34
|
+
commit_user_email: leetcoder+github-actions[bot]@users.noreply.github.com
|
35
|
+
commit_author: Name <your-name@email.address>
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'faraday/net_http'
|
5
|
+
require 'faraday/retry'
|
5
6
|
|
6
7
|
module Leetcoder
|
7
8
|
class Client
|
@@ -38,6 +39,7 @@ module Leetcoder
|
|
38
39
|
f.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true }
|
39
40
|
f.request :multipart
|
40
41
|
f.adapter :net_http
|
42
|
+
f.request :retry, retry_options
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -45,6 +47,18 @@ module Leetcoder
|
|
45
47
|
|
46
48
|
attr_reader :cookie
|
47
49
|
|
50
|
+
def retry_options
|
51
|
+
{
|
52
|
+
max: 2,
|
53
|
+
interval: 0.1,
|
54
|
+
interval_randomness: 0.5,
|
55
|
+
backoff_factor: 2,
|
56
|
+
methods: %i[get post put],
|
57
|
+
exceptions: [Errno::ETIMEDOUT, Timeout::Error, Faraday::TimeoutError, Faraday::ClientError],
|
58
|
+
retry_statuses: [500, 429]
|
59
|
+
}.freeze
|
60
|
+
end
|
61
|
+
|
48
62
|
def valid_response?(response)
|
49
63
|
return false unless (200...299).cover?(response.status)
|
50
64
|
return true unless response.body.is_a? Hash
|
@@ -72,6 +86,9 @@ module Leetcoder
|
|
72
86
|
when 200, 400
|
73
87
|
raise ApiError, "status: #{response.status},\n" \
|
74
88
|
"code: GRAPHQL_ERROR, \nerrors: #{response.body[:errors]}"
|
89
|
+
when 429
|
90
|
+
raise ApiError, "status: #{response.status},\n" \
|
91
|
+
"code: RATE_LIMIT_EXCEEDED, \nerrors: [Please try again.]"
|
75
92
|
when 404
|
76
93
|
raise ApiError, "status: #{response.status},\n" \
|
77
94
|
"code: NOT_FOUND_ERROR,\n" \
|
@@ -17,7 +17,11 @@ module Leetcoder
|
|
17
17
|
|
18
18
|
def call
|
19
19
|
Dir.chdir(@root_directory) do
|
20
|
+
log_message(:initiate_download, dir: @root_directory)
|
21
|
+
|
20
22
|
download_accepted_submissions
|
23
|
+
|
24
|
+
log_message(:completed_download)
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
@@ -28,9 +32,9 @@ module Leetcoder
|
|
28
32
|
def download_accepted_submissions
|
29
33
|
accepted_questions.each do |question|
|
30
34
|
question_dir = "#{question.frontendQuestionId}.#{question.titleSlug}"
|
31
|
-
next log_message(:
|
35
|
+
next log_message(:skip_submission, question_dir:) unless Dir.glob("#{question_dir}/*solution*").empty?
|
32
36
|
|
33
|
-
log_message(:
|
37
|
+
log_message(:submission_download, question_dir:)
|
34
38
|
|
35
39
|
Dir.chdir(create_directory(question_dir)) do
|
36
40
|
process_question(question)
|
@@ -11,10 +11,14 @@ module Leetcoder
|
|
11
11
|
|
12
12
|
def message(key, args)
|
13
13
|
case key
|
14
|
-
when :
|
14
|
+
when :skip_submission
|
15
15
|
"Skipping Download for #{args[:question_dir]}. Already Exist."
|
16
|
-
when :
|
16
|
+
when :submission_download
|
17
17
|
"Downloading sumbimissions for #{args[:question_dir]}"
|
18
|
+
when :initiate_download
|
19
|
+
"Starting download in location: #{File.expand_path args[:dir]}\n"
|
20
|
+
when :completed_download
|
21
|
+
"\nDownload completed!"
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leetcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Imam Hossain
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- README.md
|
60
60
|
- Rakefile
|
61
61
|
- bin/leetcoder
|
62
|
+
- leetcoder.yml
|
62
63
|
- lib/leetcoder/leetcoder.rb
|
63
64
|
- lib/leetcoder/leetcoder/cli.rb
|
64
65
|
- lib/leetcoder/leetcoder/client.rb
|
@@ -84,9 +85,9 @@ licenses:
|
|
84
85
|
metadata:
|
85
86
|
homepage_uri: https://www.github.com/imamrb/leetcoder
|
86
87
|
source_code_uri: https://www.github.com/imamrb/leetcoder
|
87
|
-
changelog_uri: https://www.github.com/imamrb/leetcoder/CHANGELOG.md
|
88
|
+
changelog_uri: https://www.github.com/imamrb/leetcoder/tree/v0.1.2/CHANGELOG.md
|
88
89
|
rubygems_mfa_required: 'false'
|
89
|
-
post_install_message:
|
90
|
+
post_install_message:
|
90
91
|
rdoc_options: []
|
91
92
|
require_paths:
|
92
93
|
- lib
|
@@ -101,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.3.
|
105
|
-
signing_key:
|
105
|
+
rubygems_version: 3.3.7
|
106
|
+
signing_key:
|
106
107
|
specification_version: 4
|
107
|
-
summary: A Ruby Leetcode Client to
|
108
|
-
leetcode submissions
|
108
|
+
summary: A Ruby Leetcode Client to backup accepted submissions
|
109
109
|
test_files: []
|