Repository
https://github.com/artolabs/simplesteem
New Project
SimpleSteem is a robust and reliable wrapper that dramatically simplifies the steem-python interface, expands functionality, and enables code that is gentle on public servers.
SimpleSteem was born out of necessity from developing Steemit blockchain apps while using the public steemd websocket servers. It compensates for Steem-Python's lack of exception handling, especially for server errors, and automatically retries a method call if a server did not respond appropriately. Knowing that too many rapid calls to the public servers could be interpreted as a DDOS attack, SimpleSteem uses the built in time module to wait between calls at a rate that can be adjusted in the default settings. Although this may slow down the application, it is much more gentle on the servers. This can be helpful to the developer who is not yet ready to run their app on their own server while at the same time ensuring a fair load to the public servers.
SimpleSteem:
is robust, and can run several full-time bots without failing and without over-using the servers.
integrates SteemConnect using emre's library and makes building an application that uses SteemConnect for authentication extremely easy.
uses the goodnode method (detailed in this post) to ensure a server is available before making a call.
- expands on the functionality of the Steem-Python library with extra methods and functionality such as verifying a key (both a private posting key and a SteemConnect refresh token), obtaining the reward pool balances as well as any account's balances (SBD, STEEM, Steem Power, Vote Power) with just one line of code, getting the current vote value for any account as well as grabbing the most recent post from any account.
Technology Stack
SimpleSteem is written using Python 3.5
Dependencies
SimpleSteem uses the Steem-Python library, the SteemConnect python library by emre, and ScreenLogger, a very simple class for logging what's printed to screen. All of these are automatically installed if using pip3.
Instructions For Use
There are two ways to instantiate the SimpleSteem Class. The first is to use the main account stored in the config.py file as created by the makeconfig.py module. Please see the installation instructions for more information on setting up the config.py file. To use the main account instantiate the class with no additional arguments. You may override any of the SimpleSteem method arguments.
from simplesteem.simplesteem import SimpleSteem
steem = SimpleSteem()
To instantiate SimpleSteem with your own arguments, add any of these arguments in any order. The main account must match the keys provided.
steem = SimpleSteem(mainaccount="yoursteemitaccount",
keys=['XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'],
nodes=['https://some.steemd.publicnode'],
clientid="yoursteemconnect.app",
clientsecret="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
callbackurl="https://yoursteemconnectapp.com",
permissions="login,vote,offline",
logpath="/var/log",
screenmode="quiet")
steem_instance
The steem_instance method in the SimpleSteem class is at the heart of how simplesteem works to ensure a robust connection while being gentle on steemd public nodes. Since too many calls to a public server could be interpreted as a DDOS attack, the steem_instance method as well as most of the rest of the SimpleSteem class methods use python's built in time module to wait for a certain duration in seconds between server calls. Although this may cause an app to run more slowly, it makes the app much friendlier to the public server. This can help a developer work on their app and learn the technology using public nodes before advancing to using their own node. SimpleSteem can then be converted to eliminate certain time limits, however the steem blockchain itself imposes it's own time restrictions between posts and voting and other such actions.
All of Steem-Python's methods are inherited by SimpleSteem and can be accessed through steem_instance. For example:
steem.steem_instance().get_account()
vote_history
Returns a dict of the details of the active voters of a particular post or comment as given by the argument permlink and author which both must be provided.
history = steem.vote_history(permlink, author=None)
returns dict
vote
Causes steem.mainaccount to vote on the post or comment given as the argument identifier along with a vote weight between 1 and 100.
steem.vote(identifier, weight=100.0)
returns boolean
check_balances
Uses either the account given as an argument or steem.mainaccount to get the currenct balances for SBD, STEEM, Steem Power, Vote Power, and the last time the account voted.
bal = steem.check_balances(account=None)
returns a list [float(sbdbal),
float(steembal),
float(steempower),
float(votepower),
datetime(lastvotetime)]
current_vote_value
Using the lastvotetime, steempower, voteweight, and votepower values returned from check_balances returns the current vote value in rshares. If votepower is entered as a value between 1 and 100 the vote value returned will be determined solely by that value. However, if it's in a range from 150 to 10000, which can be entered instead, the vote value returned will be caluculated including the regenerated votepower using lastvotetime. steempower must be a number between 150 and 10000. voteweight must be a number between 1 and 100.
All of these values are return by check_balances and can be used like this:
(sbd,
steem,
steempower,
votepower,
lastvotetime) = steem.check_balances(account)
r = steem.current_vote_value(lastvotetime,
steempower,
voteweight=100,
votepower)
returns a integer value in rshares
SteemConnect
The SteemConnect utilities can be accessed in a very intuitive way. Just like the SimpleSteem class uses the steem_instance method, so the utilities use the steem.connect.steemconnect method in a similar way. To use the SteemConnect methods you must either have entered a client ID, client secret key, callback url, and permissions at the time of installing SimpleSteem (see installation instructions) or have instatiated the SimpleSteem class with the same information.
auth_url
To use SteemConnect you must first access the SteemConnect website. After logging in with the given permissions, SteemConnect will redirect the user to the given callback url with ?code="XXXXXX" appended where XXXXX represenst a SteemConnect refresh token.
url = steem.connect.auth_url()
get_token
A refresh token can then be used to retrieve an access token, which is then used to authorize actions on the blockchain.
accesstoken = steem.connect.get_token(refreshtoken)
See the project README for a complete set of instructions.
Roadmap
SimpleSteem is finished in it's current state but I do plan on flushing out the SteemConnect methods a bit more. Of course I plan to continue error checking and hardening as I continue to use SimpleSteem in my various projects.
Contact
Please contact Mike on Discord
https://discord.gg/97GKVFC