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!
Very well done sha256md5. Keep up the good work. Are you running this as a *.js script? I might try this out myself too :)
Thanks @cryptonik - In order to run this you have to have node installed. You can save the file as index.js in a directory. Then run
npm init
to initialize that directory as a node project. You can just press enter for all the default values. Then you would runnpm install steem
to install the steem API package. You can then run the script by runningnode index.js
- There's also another way to just embed this into an html file and run in your browser, but that require a few minor changes. You can embed the client side library like this:<script src="https://cdn.steemjs.com/lib/latest/steem.min.js"></script>
But I haven't tried that yet.
beautiful, thanks!
Interesting. I'm getting a kick out of seeing your criteria for post selection as much as anything. I'm a new Steemian and I have been doing the same thing but examining the blockchain with SQL. I haven't decided what language I will move to yet.
Thanks. The criteria I chose for the example is totally arbitrary. I think it would probably require substantial analysis to make good "picks", but gotta start somewhere!
This post has received a 1.67 % upvote from thanks to: @sha256md5.
For more information, click here!!!!
Send minimum 0.100 SBD to bid for votes.
Before sending a transfer to @minnowhelper, verify that your publication meets these conditions (http://www.minnowhelper.com/conditions.php). After the transfer is made, no claims will be received.
The Minnowhelper team is still looking for investors (Minimum 10 SP), if you are interested in this, read the conditions of how to invest click here!!!
ROI Calculator for Investors click here!!!