A Configurable Script For Recurring Hive Curation

in Programming & Dev3 years ago (edited)

The cases for a recurring curation include preventing voting power from being wasted by sitting at 100% as well as making sure not to overlook posts from authors you wish to consistently support. There are a few other uses for it as well

Configurable Script For Recurring Hive Curation

This post describes a simple script for recurring curation using the dHive package for Node.js. The code for this script is available on GitHub.

The script described here is a slightly slimmer version of a script I use in combination with manual curation to consistently vote on my favorite hive authors without letting vote power sit idle.

Basic Usage

One simple way to run this script is to clone it, switch to the project root directory and provide minimally neccessary parameters on the command line:

git clone https://github.com/tdreid/hive-voter.git

cd hive-voter

BLOGGERS=edicted CURATOR=tdre POSTING_KEY=use_some_valid_key_for_curator LOG_LEVEL=debug npm start

Assuming a valid key is supplied this would start a loop where curator (@tdre) votes on one of the 10 latest posts by bloggers (@edicted) about every two hours (the default schedule, which is customizable as explained below)

You could also specify LOG_LEVEL=debug which has the advantage of starting off by showing you all the settings, including those not set on the command line:

$ BLOGGERS=edicted CURATOR=tdre POSTING_KEY=use_some_valid_key_for_curator npm start

> [email protected] start C:\repos\hive-voter
> node index.js

[2021-08-06T15:23:13.348] [DEBUG] default - Config {
  hiveNode: 'https://api.openhive.network',
  bloggers: 'edicted',
  maxPostsPerBlogger: 10,
  curator: 'tdre',
  voteWeight: 10000,
  postingKey: 'use_some_valid_key_for_curator',
  schedule: '* /2 * * *',
  logLevel: 'debug'
}

Full Configuration

All of the settings shown in the debug output above can be set from the command line, as exported environment variables, or using a configuration file in the config folder.

Environment Variables

For the command line or environment variables use:

HIVE_NODE
URL of the hive node to use, defaults to https://api.openhive.network

BLOGGERS
Comma delimited list of Hive users to include for potential curation

MAX_POSTS_PER_BLOGGER
An integer, this specifies the N most recent posts to lookup for each account listed in BLOGGERS. Defaults to 10

CURATOR
A single Hive account to do the voting

VOTE_WEIGHT
An integer specifies the vote weight to use as parts of 10000. For example use 10000 to vote 100%, 8501 to vote 85.01% etc.

POSTING_KEY
This string should be a valid posting key for the account specified as CURATOR

SCHEDULE
This is the recurring job schedule. It's a string in cron-style notation to define time and frequency. Its six part notation works like this:

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 means Sunday)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

The * essentially means any and you can also use the slash character (/) for divisible by. Hence the default schedule means vote every other hour, when the hour is divisible by 2:

* /2 * * *

LOG_LEVEL
Set to debug to output applied settings

The same settings can also be managed from the files in the config folder (environment variables take precedence.

Configuration Files

For complete details see the node-config package documentation.

Generally, you could set the values you need by editing config/default.json or providing override values in an environment specific files such as config/local.json:

// config/default.json
{
    "hiveNode": "https://api.openhive.network",
    "bloggers": "",
    "maxPostsPerBlogger": 10,
    "curator": "",
    "voteWeight": 10000,
    "postingKey": "",
    "schedule": "* /2 * * *",
    "logLevel": "info"
}