Get tired of manually committing your code to a Git repository everytime you have ACed a LeetCode problem?
LeetCode-Bot automatically monitors, fetches and commits your accepted LeetCode submissions to your specified Git repository.
Supports deploying as AWS Lambda function, or running on any machine with Node.js environment.
For whichever mode, AWS or Local, you need to compile the source TypeScript code first:
- Install dependencies by
yarn install
ornpm install
- Compile by
npm run build
LeetCode-Bot uses boto3 for access to AWS service APIs. Make sure proper AWS Authentication Credentials (Access Key Id & Secret Access Key) and region to deploy is specified in ~/.aws/credentials
, see This Tutorial. The provided AWS authentication credentials should at least have the permission to create S3 Bucket, Lambda Function, CloudWatch Events and IAM Policy & Roles.
We provide scripts for deploying, updating and deleting LeetCode-Bot in the AWS under ./deploy
, whose correspoding dependencies are listed in ./deploy/requirements.txt
or ./deploy/Pipfile
.
cd deploy
- Install dependencies by
pip3 install -r requirements.txt
orpipenv install
- Edit
config.yaml
for your desired settings and credentials necessary for both AWS and Git, details listed in Configuration. - Run
deploy.py
to deploy,cleanup.py
to delete all deployed services,patch.py
to rebuild and update LeetCode-Bot (if any), andupdate_session.py
to upload new LeetCode session information (Why?).
Local deployment is much simpler but it requires a host machine. After running npm run build
, use LEETCODE_SESSION=<Cookie_Value> npm start -- --config=<path_to_config>
to start LeetCode-Bot. An example of the configuration file is ./local-config-example.json
, details explained in Configuration.
Note:
LEETCODE_SESSION
is an environment variable required by LeetCode-Bot (Details Here). It can be provided in command-line, or by creating a.env
file at the root of this project with the contentLEETCODE_SESSION=...
.- LeetCode-Bot only runs One Iteration for each
npm start ...
, which fetches and processes only the oldest unfetched few (~100) submissions. This is in order to limit the frequency of LeetCode API calls. You can use tools likecron
to create a scheduled LeetCode-Bot.
git.username
&git.email
: username and emails recorded in the git commits.git.relCodeDir
: the relative path to the directory where code files will be committed in the repository.
Since LeetCode uses Recaptcha to prevent from bots, we need to use the LEETCODE_SESSION
cookie that is set when you sign in from the browser, to avoid the signin process.
In general, we use AWS Lambda triggered periodically by CloudWatch events, and S3 buckets to store Bot history.
Well, these services have free tiers and in normal cases it should be fine.
This is to avoid long running time as AWS Lambda charges based on the running time and memory usage.
Distributed under the MIT License. See LICENSE for more information.
TODOs:
- Telegram Notification
- DynamoDB instead of S3