As a brand new Steemian, I'm immediately excited about what the platform has to offer, but one of the first constraints I noticed is that content discovery is actually quite hard, because browsing is somewhat limited to a coupling of trending, new, hot, and promoted posts with tags. Posts are also displayed in mostly chronological order and sometimes tend to just fly by quite fast under highly active tags.
Content discovery is quite important on Steemit, because successful curation is so heavily incentivized, so I started to wonder if there's a way to reduce the noise and filter out just the posts that I would be actually interested in upvoting. My search led me to the API and the steem-js library:
https://github.com/steemit/steem-js
The library does have a fair amount of gaps in the documentation, but the functionality kicks ass, so I feel inspired to share what I find as I continue to learn and play with it. This post is meant to serve only as a gentle introduction, but I hope to build on some simple concepts to inspire some bot builders out there.
Let's start by writing a little script that pulls a bunch of new posts, but removes anything with more than a couple of upvotes and from authors with a reputation of less than 40. These are arbitrary numbers, but the reasoning is that content from a higher rep user is more likely to be interesting and less than a handful of upvotes still presents an opportunity to jump in as a curator.
let steem = require('steem');
steem.api.setOptions({ url: 'https://api.steemit.com' });
let rules = {
rep: 40,
votes: 3
}
function simpleRep(r){
return Math.floor((((Math.log10(r)-9)*9)+25));
}
function buildPermlink(p){
return "http://steemit.com/" + p.category + "/@" + p.author + "/" + p.permlink;
}
function checkPost(p) {
let r = simpleRep(p.author_reputation);
if ((r > rules.rep) && (p.net_votes < rules.votes) && p.allow_curation_rewards){
console.log(p.title, p.net_votes, "\n", p.author, r, "\n", buildPermlink(p), "\n\n");
}
}
let query = {
tag: '',
limit: 100
};
steem.api.getDiscussionsByCreated(query, function (err, discussions){
discussions.map((d) => { checkPost(d); });
});
Let's take a closer look at what we're actually doing. First, we load the steem API and set the API endpoint.
let steem = require('steem');
steem.api.setOptions({ url: 'https://api.steemit.com' });
Then we set our constraints:
let rules = {
rep: 40,
votes: 3
}
Define a function to convert the reputation to the simplified reputation we're used to:
function simpleRep(r){
return Math.floor((((Math.log10(r)-9)*9)+25));
}
Define a function to build the url that will link us to the post. This function takes a discussion object as an argument:
function buildPermlink(p){
return "http://steemit.com/" + p.category + "/@" + p.author + "/" + p.permlink;
}
Then a function to check if a post fits with the constraints that we've defined above. If the post fits our constraints, we format some basic information about it and write it to the console:
function checkPost(p) {
let r = simpleRep(p.author_reputation);
if ((r > rules.rep) && (p.net_votes < rules.votes) && p.allow_curation_rewards){
console.log(p.title, p.net_votes, "\n", p.author, r, "\n", buildPermlink(p), "\n\n");
}
}
Define a query object. This object is a required parameter for our api call to get the newly created posts. Here we say that we want all posts instead of those from a specific tag, and that we want 100 results:
let query = {
tag: '',
limit: 100
};
Finally, we make the API call and then call our function to process the posts against our constraint:
steem.api.getDiscussionsByCreated(query, function (err, discussions){
discussions.map((d) => { checkPost(d); });
});
When run, the code should produce a block of entries that looks something like this:
[excerpt]
WISATA BERSAMA KELUARGA #part II 0
hasanuddin 53
http://steemit.com/indonesia/@hasanuddin/wisata-bersama-keluarga-part-ii
Daily Food Photography (Dinner with Japanese) 0
world-food 44
http://steemit.com/dinner/@world-food/daily-food-photography-dinner-with-japanese-925081227b402
[excerpt]
At this point, we have successfully been able to connect to the Steemit API, Pull the 100 most recent posts, and filter out the ones that we might find interesting based on our own user defined constraints. So what's next?
Well there's really no limit to the direction that we can take this. Perhaps we can adapt the code for the browser so that we can have a form to toggle our constraints, browse, and upvote without having to re-run the script. Or maybe it eventually becomes a full-fledged curation helper bot! Either way, it's a humble beginning to deeper interaction with the Steemit platform.
--
Thank you all for reading this far. If you found this a useful introduction to automation with the Steemit API, please consider leaving a comment below with what direction you would like to see future posts in this series go toward.
Happy scripting!