HackerRank Sync is a fork of Apparate, a command line tool to synchronize your HackerRank submissions to a GitHub Repository.
Enter apparate
in the terminal, give it your credentials, and it will sync your submissions automatically.
You can also schedule a cron job to run apparate regularly & keep your submissions up to date.
Usage: apparate [OPTIONS]
Options:
--repo TEXT Name of the GitHub repository to store submissions
--user TEXT Username of your HackerRank account
--pword TEXT Password of your HackerRank account
--token TEXT GitHub access token with all repo privileges
--help Show this message and exit.
- Replace deprecated dependencies
- Implement GitHub API via
requests
instead ofPyGithub
- Update find_element methods and CSS selectors in
spider.py
to support new HackerRank UI
Feel free to contribute to this project by opening a pull request.
Apparate uses Python Selenium and Firefox for fetching data from HackerRank. It utilizes the GitHub REST API v3 to manage your submissions repository.
Here are the instructions to install Apparate on Linux and macOS platforms. Feel free to skip any steps which your system already satisfies accordingly.
Steps:
-
Environment setup
-
Apparate setup
Optional: You may also want to schedule a cron job to run Apparate regularly. For that, follow these instructions,
-
Cron job setup
- Change to your local timezone (required for remote deployment, ex- AWS EC2 instance)
- Schedule cron job
To update and upgrade your system, run the following command,
sudo apt update && sudo apt upgrade
Firefox geckodriver is required to use Selenium.
-
Download Firefox from Mozilla.
-
Go to the geckodriver releases page. Find the latest version of the driver for your platform (32 bit or 64 bit) and download it. For example:
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.33.0-macos.tar.gz
- Extract the file with:
tar -xvzf geckodriver*
- Make it executable:
chmod +x geckodriver
- Add the driver to PATH in your
~/.profile
so that Selenium can find it:
export PATH="/<path-to-extracted-file>:${PATH}"
- Test it by re-opening terminal & executing
geckodriver
from another directory. If that doesn't work, perform step 5 again with~/.bashrc
file instead of~/.profile
.
-
Python 3: Install using
sudo apt-get install python3
-
pip3: Install using
sudo apt-get install python3-pip
- Clone or download this repository
git clone https://github.com/taylorsudo/hackerrank-sync.git
- Install this fork of
Apparate
by executing following command inside thehackerrank-sync
directory:
pip3 install --editable .
- To verify the installation, execute:
apparate --help
it should give the following output:
Usage: apparate [OPTIONS]
Options:
--repo TEXT Name of the GitHub repository to store submissions
--user TEXT Username of your HackerRank account
--pword TEXT Password of your HackerRank account
--token TEXT GitHub access token with all repo privileges
--help Show this message and exit.
- Run and test Apparate as follows:
apparate --repo <your-github-repo> --user <hackerrank-username> --pword <hackerrank-password> --token <github-token>
Most of the cloud virtual machine instances (e.g. AWS EC2) use UTC
by default. Before scheduling apparate with crontab, verify if your machine is using correct timezone. If not, then change timezone of your machine to your local timezone.
For that, you may use timedatectl
by:
-
Listing all available timezones using
timedatectl list-timezones
-
Setting your timezone using
sudo timedatectl set-timezone Australia/Sydney
For example, to set machine timezone to Australia/Sydney
, you may run,
sudo timedatectl set-timezone Australia/Sydney
Note: To get cron to launch programs according to local time, change /etc/localtime
to be a symbolic link to the appropriate tzfile
for your timezone, and then restart the cron service:
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime
service cron restart
To schedule a cron job, you can write cron expressions. To learn more about cron jobs and scheduling, follow this guide by DigitalOcean: How To Use Cron To Automate Tasks On a VPS.
To add a cron job, run crontab -e
and input down your schedule expression and the file. Make sure to add your crontab file to your PATH, so that Apparate & geckodriver can be found. You can list all the scheduled crontabs of a user by running crontab -l
Example cron file for Apparate to execute daily at 4 AM:
# Add all directories in `~/.local/bin` to $PATH
export PATH="$PATH:$(find ~/.local/bin -type d | paste -sd ':' -)"
# Schedule cron job for Apparate
0 4 * * * apparate --repo <your-github-repo> --user <hackerrank-username> --pword <hackerrank-password> --token <github-token> --token "GitHub_Token" >> ~/cron_apparate.log 2>&1
The above example saves command logs to a file called cron_apparate.log
in your home directory.
Contributions are welcome to to add support for more platforms (e.g. Codefchef, Codeforces, etc.), improve existing code, update documentation or add new features. To start contributing, fork this repository, make changes, and open a pull request with your changes.