Coder Social home page Coder Social logo

hackerrank-sync's Introduction

HackerRank Sync

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.

TODO

  • Replace deprecated dependencies
  • Implement GitHub API via requests instead of PyGithub
  • 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.

How to use

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:

Optional: You may also want to schedule a cron job to run Apparate regularly. For that, follow these instructions,

Update and upgrade your OS

To update and upgrade your system, run the following command,

sudo apt update && sudo apt upgrade

Install Firefox and geckodriver

Firefox geckodriver is required to use Selenium.

  1. Download Firefox from Mozilla.

  2. 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
  1. Extract the file with:
tar -xvzf geckodriver*
  1. Make it executable:
chmod +x geckodriver
  1. Add the driver to PATH in your ~/.profile so that Selenium can find it:
export PATH="/<path-to-extracted-file>:${PATH}"
  1. 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.

Install Python 3 and pip3

  1. Python 3: Install using sudo apt-get install python3

  2. pip3: Install using sudo apt-get install python3-pip

Download and install Apparate

  1. Clone or download this repository
git clone https://github.com/taylorsudo/hackerrank-sync.git
  1. Install this fork of Apparate by executing following command inside the hackerrank-sync directory:
pip3 install --editable .

Validate and test installation

  1. 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.
  1. Run and test Apparate as follows:
apparate --repo <your-github-repo> --user <hackerrank-username> --pword <hackerrank-password> --token <github-token>

Change to your local timezone

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:

  1. Listing all available timezones using timedatectl list-timezones

  2. 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

Schedule cron job

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

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.

hackerrank-sync's People

Contributors

sanketgautam avatar taylorsudo avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.