These updates and fixes apply to the Steem-Bash Project from revision #0c4d81a to #50a3ac98.
I spent a long while playing with the different get_discussions_by_*
functions and I've come to realize that I need a better way of handling them. But that will be in a future update. For this update I've tentatively improved the arguments they take and corrected a number of improperly passed limit
values. I've also added a new script that makes use of gnuplot to display price data over time. This script was something of an experiment as I'm hoping a future update will include the use of gnuplot to show earnings over time. But I'm getting ahead of myself.
Bug Fixes
- fixed an errant -j (should have been -r) to
jq
when parsing vote information for notifications innotify.sh
- fixed limit value passing
- fixed missing endpoint
New Features
Added a new script that allows graphing arbitrarily many altcoins in gnuplot using a user specified currency.
- notify.sh #fee9ee224
Added options for notifying on:
- specific operations for specified user
- specific operations for followers of the specified user
And added options for ignoring certain followed users of the specified user.
functions.sh
I added get_comment_discussions_by_payout
and took a long hard look at the arguments passed to the various get_dicussions_by_*
functions that take a "query" object. Although many of the functions take this common object, they don't all treat it the same way or make use of the same elements from it, so I'm still at a bit of a loss on how to better expose all of these options. I've tried to expose the elements from the object that these methods use, and I have updated several of them accordingly, but it's still an imperfect solution. In an ideal world, I could build up an object using an associative array so that it would mirror the JSON object, but passing associative arrays in Bash is generally only accomplished with an egregious hack. I may end up creating some convenience methods that operate on a JSON string and prepare this string for use in a function call, but I'm still working this.
Other updates to functions.sh
include fixing the get_discussions_by_cashout
and get_discussions_by_payout
so that pagination works correctly, updating rpc_get_reward_fund
so that the specific reward fund is not hardcoded to "post" but instead is configurable and defaults to post. A number of functions now have the correct data type for their limit
arguments. And the get_liquidity_queue
function was added.
Also moved inlist
and listinlist
functions from some of the sample scripts into functions.sh
so they could be used by other scripts.
graphcoins.sh
Even though I had that handy ticker to display the prices in near real time, I found myself wondering how the current price came to be. Rather than pull up some random web site that's full of a bunch of content I don't want to see, and would rather not wait for loading, I decided to take a look at the gnuplot
command. The real challenge wasn't in getting gnuplot
to show prices over time, it was in minimizing the number of files that needed to live on the disk for gnuplot
to be able to draw a graph and get the plot data from somewhere. I managed to at least eliminate the need for a file that tells gnuplot
where to look for the file with the data in, and I used the same exit hook that I originally used in other scripts so that the temp files are cleaned up on exit, so I'm somewhat pleased with the result.
The results of the script, showing STEEM and SBD as I edit this writeup:
There aren't a lot of bells and whistles, but it can take any number of altcoins you want to see and display them as it fetches their prices from cryptocompare. I originally had it displaying BTC and LTC along with STEEM and SBD, but that shoved the STEEM and SBD lines together along the bottom of the graph and BTC was so far away from it that it similarly looked like a straight line. Interesting, but not very informative for seeing the tiny ups and downs of SBD and STEEM.
This script creates a temporary file to store the data points and sets a trap to remove this temporary file on exit. It fetches the initial coin values via the following function:
##
# Appends a line of price data to the specified file.
appendline(){
local ALTCOINS=${1}
local FILE=${2}
local CURRENCY=${3}
local PRICES
PRICES=$(get_prices "${ALTCOINS}" "${CURRENCY}")
if [ $? -eq 0 ] ; then
echo -n "$(date +"${DATEFMT}")" >> "${FILE}"
for COIN in ${ALTCOINS} ; do
echo -n " $(jq -r ".${COIN}.${CURRENCY}" <<< $PRICES)"
done >> "${FILE}"
echo >> "${FILE}"
fi
}
The entire list of altcoins to be processed is sent as the first argument, the temporary file as the second, and the currency to use as the third argument. It fetches the entire list of coin values in one shot to avoid making unnecessarily many requests against cryptocompare. You can make a ridiculous number of requests before they stop answering them, but that's no reason not to minimize the number made. Once it has all of the coin values, it loops over each coin, outputting their value one per column (of course) to a single line of the temporary file.
This is invoked once at the beginning to create the initial plot point so that gnuplot will have some data before it's launched, and then a loop is forked into the background that calls it repeatedly until the script exits. The code for that is fairly straightfoward.
# spawn background task of updating prices
while true ; do
sleep "${SLEEP}"
appendline "${ALTCOIN[*]}" "${TEMPFILE}" "${CURRENCY}"
done &
The only thing that might be odd about this is that the while loop itself is forked into the background, as opposed to forking a function or single command. This is something supported by bash, but I don't see a lot of scripts doing it.
Next, a subshell is launched and it continues to feed instructions to gnuplot
so that it keeps updating the graph.
(
echo "set timefmt '"$DATEFMT"'"
echo "set xdata time"
echo "set datafile separator '\t'"
echo 'set format x "%m/%d\n%H:%M:%S"'
while true ; do
cat << EOF
$(echo -n plot) $(for ((i=0;i<"${#ALTCOIN[@]}";i++)) ; do echo -n " '$TEMPFILE' using 1:$((i+2)) with line title '${ALTCOIN[${i}]}' "; if [ "$((i+1))" -ne "${#ALTCOIN[@]}" ] ; then echo -n ','; fi; done)
reread
EOF
sleep "${SLEEP}"
done ) | gnuplot
Here, the subshell does some one-time setup stuff, namely the date format as it is used in the data file, configuring the x axis to be time based, and configuring the separator to be a tab (a space is used in the date format, so we can't use that here. Then an infinite loop is used that repeatedly tells gnuplot
to plot a line from the file and re-read the file, and then the loop sleeps before starting again.
notify.sh
The notifications script got some more attention as it turns out certain curation trails generate a ton of activity, and as the day progresses, I tend to modify the options to see more or less activity for certain things, so I've made these all tunable.
The script can handle any of the following operations it sees on the block:
- comment
- vote
- author_reward
- curation_reward
- transfer
Nothing too new there, but now, with the -t option the user can pick which of these things they actually care about. Pass the option and only the items named will show up. Leave the option off and everything shows up.
But that wasn't good enough, because sometimes I want to see all of these fields for myself, but only comments and votes for people I'm following. So I can now pass the -T option and specify just the types of operations that I specify for the people I'm following.
But that wasn't good enough either, because even with cutting out votes and only showing comments, I was seeing a lot of activity from curation trails that I didn't need to see. So, I added an exclude option and now I can exclude the accounts I follow for posts, but don't usually want to see unless I'm reading my feed.
The result is that I can leave this running and the Steem block chain feels like a much more active place because I'll see notifications of comments going back and forth on threads that I wouldn't otherwise have noticed unless I had the tab sitting open and I was constantly refreshing the page.
Plans
I'm going to create a graph using payout and reward data so I can see what rate money goes in to or out of any given account next. After that, I'm going to resume implementing the remaining database API functions and then I'm going to look at ways to accomplish the crypto signing so I can possibly execute block operations from bash. I have a hunch that this will use openssl as a back end, but we'll see.
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @not-a-bird I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit