Bugs Fixed, Features Added

in #utopian-io7 years ago (edited)

Bug Fixes

Discovered these issues while running the scripts and playing with the functions in functions.sh.

New Features

Moved ticker style functionality to its own function and put it into functions.sh ee3dfc15a3ffc8ff0e0f337c84ae787fdf4ecde2.

Created balances.sh f12da076103377308e38b953983f55443ccb3d30 to replace all of the ticker scripts and provide new functionality:

  • added argument parsing to enable output
    User can choose
    • display full account value
    • display balances (sbd, steem, savings) [default]
    • display SP
    • display pending payouts [new] added here and then here
  • made ticker format optional (can do one-shot and exit)
  • added ability to display other output currencies (try LTC, for example) [new]
    This is used for:
    • full account value option
    • pending payout option
  • added ability to specify the service endpoint (future proofing) [new]
  • minimized external service calls (speedup)
  • How did you implement it/them?

The pending payout calculation is the full pending payout, before subtracting any curation. Little more to do here, but good start. It was implemented using the rpc_get_discussions_by_author_before_date, giving it the provided author and today's date as a starting point and going back to the last N posts (10 originally, updated to be configurable).

This is how the get_payout function was implemented:

##
#     get_payout <AUTHOR> <LIMIT> [ENDPOINT]
# Gets the specified author's pending payouts as a sum of SBD.
get_payout(){
    local AUTHOR=${1}
    local WHEN=$(date -Iseconds)
    local LIMIT=${2:-}
    local PAYOUTS=$(rpc_get_discussions_by_author_before_date "${AUTHOR}" '' "${WHEN}" "${LIMIT}" "${ENDPOINT}" | grep -Po '"pending_payout_value":.*?[^\\]",' | cut -f2 -d:  | cut -f2 -d'"' | cut -f1 -d' ' | xargs)
    VALUE=$(math "$(sed 's/ /+/g' <<< "${PAYOUTS}")" 2)
    echo "${VALUE}"
}

The get_discussions_by_author_before_date rpc call is used because it looked like the only one that clearly filtered based on author. The tag field is simply left empty to get all posts before the current moment.

The original project author mentioned possibly moving away from jq, so I used grep as an example of how to extract json values. The actual pending payout values are of the form "000.000 SBD" so the value needed to be cut on the space to discard the SBD but otherwise extracting the value is pretty clear. Then The list of payout values it added together using the original author's math function. The values are built up with a sed expression. Finally, the value is returned in SBD.

Back in the balances.sh script, the value is also displayed in whatever currency the user passes in. This is accomplished by propagating the CURRENCY value through the CURRENCY global to the get_prices function so that the SBD value can just be multiplied by that result.

Added some functions to fetch just SP, STEEM, and SBD f381a3df70661a2c6d6ca8424718d644fae1c689. Originally these were in a new example script, but I made this script obsolete when I moved balances_ticker.sh to just balances.sh and added all of the new options f12da076103377308e38b953983f55443ccb3d30. It was too slow to fetch the various fields one at a time, so the method fetches the account information and then calculates the rest. At the same time, I added a CURRENCY option to balances.sh so that it could be used in calculating other dollar values of account assets.

The ability to choose which elements are displayed is new. Calculating pending payouts is new. Displaying in other currencies was supported by aspects of the architecture, but it wasn't being passed through nor being used in calculating values, so while the functions for fetching currency values already existed, making use of them and doing the extra calculations is new.

The output of the new balances.sh is much clearer than the previous ticker.

ticker screenshot

I don't know how to make animated gifs, but I updated the README to include text examples of the new output and features.


Updated content for the readme:

There are some example scripts, they all take a minimum, one or more account names.

worth.sh - original one-shot example for fetching account value
balances.sh - an uber example ticker or one-shot script

The worth.sh script is a very basic example that only supports a user name.

Example:

$ worth.sh not-a-bird
1577.120

The balances.sh supports more options and multiple user names.

Usage:
    balances.sh [-b] [-c CURRENCY] [-e RPC_ENDPOINT] [-s] [-t] [-w] [-p] [-h] <USER> [USER ...]"

Get and display balance information about the specified user.

- b show balances (sbd, steem, savings) [default when no options specified]
- c CURRENCY (default is USD)
- e specify service node endpoint
- h show help
- p include pending payouts in output
- s include SP in output
- t enable stock ticker output
- w include total account worth in output

Examples:

$ balances.sh -b not-a-bird
not-a-bird  1.899 STEEM 2.027 SBD 1.000 Savings

$ balances.sh -w not-a-bird
not-a-bird  worth: 1,157.77 USD

$ balances.sh -c LTC -w not-a-bird
not-a-bird  worth: 6.00 LTC

$ balances.sh -p not-a-bird
not-a-bird  pending payout: 248.86 SBD (USD: 1072.587)

$ balances.sh -p -c BTC not-a-bird ned
not-a-bird  pending payout: 248.87 SBD (BTC: 0.095)
ned  pending payout: 0.00 SBD (BTC: 0.000)

$ balances.sh -bpw -c BTC not-a-bird ned
not-a-bird  worth: 0.10 BTC 1.899 STEEM 2.027 SBD 1.000 Savings pending payout: 248.88 SBD (BTC: 0.094)
ned  worth: 1,452.40 BTC 141871.305 STEEM 5743.288 SBD 0.000 Savings pending payout: 0.00 SBD (BTC: 0.000)

My Fork here and original project here.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Hey @evilest-fiend I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

The link for your fork points to not-a-bird's repo.
Assuming this is you: https://github.com/evilest-fiend/steem-bash

Nice catch! Updated.

Thanks!

Thank you for the contribution. It has been approved.
What will be the next feature you will be going to add?

You can contact us on Discord.
[utopian-moderator]

What will be the next feature you will be going to add?

I don't know. I really just wanted the pending payout calculation because steemworld.org is so slow. Maybe something to send me notifications when there are posts by people I am following.

Congratulations @evilest-fiend! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @evilest-fiend! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @evilest-fiend! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @evilest-fiend! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:

SteemitBoard Ranking update - Resteem and Resteemed added

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @evilest-fiend! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 7000 upvotes. Your next target is to reach 8000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @evilest-fiend! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemFest⁴ commemorative badge refactored
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @evilest-fiend! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 14000 upvotes. Your next target is to reach 15000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP