Skip to content

Instantly share code, notes, and snippets.

@driversti
Last active June 13, 2023 19:11
Show Gist options
  • Save driversti/71b5ca50a6bb55c64da4282c65e4d7e3 to your computer and use it in GitHub Desktop.
Save driversti/71b5ca50a6bb55c64da4282c65e4d7e3 to your computer and use it in GitHub Desktop.

Get Started with the Profile Statistic Script

Here's a step-by-step guide on how to run the profile statistic script either with Node.js or Docker.

Prerequisites

  • A computer running a GNU/Linux or macOS operating system.
  • Basic knowledge of the command-line interface.
  • Administrator (root) access to your machine.

1. Running with Node.js

First, you need to install Node.js and the Node Version Manager (nvm).

Installing Node Version Manager (nvm)

Open your terminal and run the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Close your terminal and open it again, then verify the installation with:

nvm --version

# output
0.39.0

Installing Node.js with nvm

Now install Node.js with this command:

nvm install node

You can verify your Node.js installation with this command:

node --version

# output
v18.6.0

Important! Prior to run the script create a folder data in your home directory where a CSV file with the statistics will be saved!

Running the Script Manually

Assuming that bundle.js is located in your home directory, you can run it with a simple script:

# create a new file
touch ~/run_profile_statistic.sh

Open the file with your favorite text editor and paste the following code (including #!/bin/bash !!!). The language can be any of used by eRepublik ("en", "ua", "pl", "it", etc)

#!/bin/bash
export ERPK_EMAIL="your-email@example.com"
export ERPK_PASSWORD="your-password"
export ERPK_LANG="en"
node ~/bundle.js

Automating the Script with cron

Open your crontab file with this command:

crontab -e

Add the following line to run the script every day at 7 AM (adjust the time to your preference):

0 7 * * * ERPK_EMAIL="your-email@example.com" ERPK_PASSWORD="your-password" ERPK_LANG="en" /home/username/.nvm/versions/node/$(node -v)/bin/node /home/username/bundle.js >> /home/username/profile_stats.log 2>&1

Press CTRL+X, then Y, then Enter to save and exit.

The profile_stats.log file will be created in your home directory and will contain the output of the script. It will be helpful for debugging.

2. Running with Docker

First, you need to install Docker on your machine.

Installing Docker

Follow the official Docker installation guide for your specific operating system: https://docs.docker.com/get-docker/

Don't forget to follow the post-installation steps to manage Docker as a non-root user: https://docs.docker.com/engine/install/linux-postinstall/

Important! Prior to run the script create a folder data in your home directory where a CSV file with the statistics will be saved!

Running the Docker Image

Assuming that the Docker image is already built and named driversti/erep-profile-stats, you can run the image with the following command:

docker run --rm -e ERPK_EMAIL="your-email@example.com" -e ERPK_PASSWORD="your-password" -e ERPK_LANG="en" -v "/home/username/data":"/app/data" driversti/erep-profile-stats:latest

Automating Docker Image Execution with cron

Open your crontab file:

crontab -e

Add the following line to run the Docker image every day at 7 AM:

0 7 * * * /usr/bin/docker run --rm -e ERPK_EMAIL="your-email@example.com" -e ERPK_PASSWORD="your-password" -e ERPK_LANG="en" -v "/home/username/data":"/app/data" driversti/erep-profile-stats:latest >> /home/username/docker_profile_stats.log 2>&1

Press CTRL+X, then Y, then Enter to save and exit.


And that's it! You now have the script set up to gather profile statistics either manually with Node.js, or inside a Docker container, or automatically with cron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment