Apparate is a command line tool to synchronize your HackerRank Accepted Submissions to your GitHub Repository.
Just write apparate
on terminal, give it your credentials, sit-back and relax, it'll take care of the rest.
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 GitHub repository to store submissions
--user TEXT Username of your HackerRank account
--passwd TEXT Login Password of your HackerRank account
--token TEXT GitHub Access Token with all repository privileges
--help Show this message and exit.
It's built with Python Selenium and uses Firefox binary for fetching data from HackerRank. It used GitHub REST API v3 to manage submissions repository. Here are the instructions to install apparate on Ubuntu 16.04 LTS. Other platforms may have similar requirements. 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,
-
Scheduling cron Job to update regularly
- Change to your Local Timezone (required for remote deployment, ex- AWS EC2 Instance)
- Schedule Cron Job
Contributions are welcome to apparate to add support for more platforms (ex- Codefchef, Codeforces etc.), improve existing code, update documentation or add new features. To start contributing fork this repository, make changes and send a pull request with your changes.
To update and upgrade your system, run the following command,
sudo apt update && sudo apt upgrade
Firefox geckodriver required for selenium,
-
Go to the geckodriver releases page. Find the latest version of the driver for your platform (32 bit/ 64 bit) and download it. For example:
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz
-
Extract the file with:
tar -xvzf geckodriver*
-
Make it executable:
chmod +x geckodriver
-
Add the driver to your PATH so selenium can find it: add
export PATH=$PATH:/path-to-extracted-file/geckodriver
to your~/.profile
and then executesource ~/.profile
Test it by re-opening terminal & executing geckodriver
from another directory. If that doesn't works, perform step 4 again with ~/.bashrc
file instead of ~/.profile
.
Follow these instructions to install firefox [install Firefox 59.0.2 to avoid any compatibility issues]
-
Download Firefox v59.0.2 from Mozilla FTP using
wget
, example, for 64 bit systemswget https://ftp.mozilla.org/pub/firefox/releases/59.0.2/linux-x86_64/en-US/firefox-59.0.2.tar.bz2
-
Extract the tar package
tar -xjf firefox-59.0.2.tar.bz2
-
Move the Firefox folder to opt & remove the Older version of Firefox if it's there
sudo rm -rf /opt/firefox58 (only if firefox58 is already installed) sudo mv firefox /opt/firefox59
-
Create the symbolic link for new Firefox
sudo mv /usr/bin/firefox /usr/bin/firefoxold (only if any other version of firefox is already installed) sudo ln -s /opt/firefox59/firefox-bin /usr/bin/firefox
Verify installation by running firefox --version
, if it throws any errors, then also install these required dependencies,
sudo apt-get install libgtk-3.0
sudo apt-get install xvfb
Python3: It is already installed on new versions of Ubuntu, if not it's easy to install using apt-get
pip3: Install it using apt as sudo apt-get install python3-pip
-
Clone or Download Apparate Repository
git clone https://github.com/sanketgautam/Apparate.git
-
Now install
Apparate
by executing following command inside Apparate/ directorypip3 install --editable . (installing setup.py)
To verify the installation, execute
apparate --help
it should give the following output,
Usage: apparate [OPTIONS]
Options:
--repo TEXT Name of GitHub repository to store submissions
--user TEXT Username of your HackerRank account
--passwd TEXT Login Password of you HackerRank account
--token TEXT GitHub Access Token with all repository privileges
--help Show this message and exit.
Run and Test Apparate as follows.
apparate --repo <Submissions_Repo_Name> --user <HackerRank_Username> --passwd <HackerRank_Password> --token <GitHub_Token>
Most of the cloud virtual machine instances (ex- 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, may use timedatectl
as,
-
To list all available timezones use
timedatectl list-timezones
-
To set timezone use
sudo timedatectl set-timezone Asia/Kolkata
For example, to set machine timezone to Asia/Kolkata
, you may run,
sudo timedatectl set-timezone Asia/Kolkata
Note: To get cron to launch programs according to local time, I had to change /etc/localtime
to be a symbolic link to the appropriate tzfile
for my timezone, and then restart the cron service:
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
service cron restart
To schedule a cron job, you can write cron expressions.To learn more about cron jobs & scheduling follow this nice article by DigitalOcean - How To Use Cron To Automate Tasks On a VPS
To add a contjob crontab -e
and write down your schedule expression & and the file. Also make sure to add PATH variable to your crontab file, so that apparate & geckodriver can be found. You can list all the scheduled crontabs of a user by crontab -l
Example cron file for apparate (to execute it daily at 4 AM):
# setting shell and path for execution
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/
# apparte cron expression
0 4 * * * apparte --repo "Submissions_Repository_Name" --user "Your_HackerRank_Username" --passwd "Your_HackerRank_Password" --token "GitHub_Token" >> ~/cron_apparate.log 2>&1
Above given example cron jobs saves command logs to cron_apparate.log
in users home directory.