Hacking Steem with Python in the Cloud

in #python7 years ago (edited)

Like the ocean...

<p dir="auto">One of the coolest (and hardest to comprehend) things about Steem is that it is an ecosystem. There are tons of different <a href="https://steemit.com/steemdev/@inquiringtimes/steem-web-resources-tools-apps-communities-ect" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">tools and platforms that all plug into the same fundamental features offered by the blockchain. Anyone can communicate with the network's public nodes or run their own, to access posts, make votes, transfer Steem/SBD, etc., all without using a front end like Steemit. <p dir="auto"><center><img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmXxZRxeKd3ieSLmffFm5jND4e5rrtrPETBws11CN6pTMx/DeepinScreenshot_select-area_20180206193121.png" alt="DeepinScreenshot_select-area_20180206193121.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmXxZRxeKd3ieSLmffFm5jND4e5rrtrPETBws11CN6pTMx/DeepinScreenshot_select-area_20180206193121.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmXxZRxeKd3ieSLmffFm5jND4e5rrtrPETBws11CN6pTMx/DeepinScreenshot_select-area_20180206193121.png 2x" /> <p dir="auto">This enables projects like Busy, ChainBB, Dtube, and Utopian, just to name a few. Learning about new projects like <a href="https://steemit.com/steem/@fredrikaa/steempress-now-available-in-the-wordpress-org-plugin-store-introducing-v1-0" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">SteemPress through the Utopian feed got me inspired to try writing a bit of code that interfaces with Steem. Getting started involved a few challenges, so I decided to write this guide to show how to get started programming Steem with nothing more than a web browser and some free tools. <h2>Python <p dir="auto">Python is my weapon of choice for programming. If you're thinking about learning, it's a great place to start. If you already know some, this should be easy to follow along with. Just about everything has a library for Python (to be specific, we'll be talking about Python 3 throughout), and <a href="https://steem.readthedocs.io/en/latest/index.html" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Steem is no exception. With the library installed, we can use Python to run commands that interact with the blockchain via Steem's REST API. Don't freak out if things are getting a little technical here, we'll do this all in a web browser with step by step instructions. <h2>Codenvy <p dir="auto"><a href="https://codenvy.com" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Codenvy is a cloud based development platform that offers a nice free plan. Creating an account is <a href="https://codenvy.io/site/create-account" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">simple—go ahead and make one now. We'll need a workspace to hold our files and provide the underlying operating system to run Python on. Go to your dashboard on Codenvy and select the "Create Workspace" button. Then select "Single Machine," scroll down the list and select "Debian," then press the green "Create" button. <p dir="auto"><center><img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmcDh9JaA5zum9yrJKjj3MFYm8bKXXnyKjZXGqrjV6XFsD/DeepinScreenshot_select-area_20180211155006.png" alt="DeepinScreenshot_select-area_20180211155006.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmcDh9JaA5zum9yrJKjj3MFYm8bKXXnyKjZXGqrjV6XFsD/DeepinScreenshot_select-area_20180211155006.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmcDh9JaA5zum9yrJKjj3MFYm8bKXXnyKjZXGqrjV6XFsD/DeepinScreenshot_select-area_20180211155006.png 2x" /> <h2>Install <p dir="auto">Now we need to install Python and steem-python. We'll use Miniconda to provide a complete and up to date Python installation, then use pip to install steem-python. <h3>Miniconda <p dir="auto">Once your workspace has loaded up in Codenvy, you should have a terminal window at the bottow. Run the following commands in the terminal to download and run the Miniconda installer: <pre><code>wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh chmod u+x Miniconda3-latest-Linux-x86_64.sh ./Miniconda3-latest-Linux-x86_64.sh <h3>Scrypt Dependencies <p dir="auto">Scrypt is one of the libraries that steem-python depends on. It in turn has a couple dependencies we'll need to install with Debian's package manager, apt-get: <pre><code>sudo apt-get install build-essential libssl-dev <h3>steem-python <p dir="auto">Finally, we can install steem-python using pip: <pre><code>pip install steem <h2>Patch METADATA <p dir="auto">There's a little hickup in steem-python to do with the version number of one of its dependencies, toml. To see the problem in action, try running the command line tool, <code>steempy: <p dir="auto"><img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmdfVroZYypdXxMMhhzq7jHkjxXMtJptsGSZfrj5bRdWh1/DeepinScreenshot_select-area_20180211165234.png" alt="DeepinScreenshot_select-area_20180211165234.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmdfVroZYypdXxMMhhzq7jHkjxXMtJptsGSZfrj5bRdWh1/DeepinScreenshot_select-area_20180211165234.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmdfVroZYypdXxMMhhzq7jHkjxXMtJptsGSZfrj5bRdWh1/DeepinScreenshot_select-area_20180211165234.png 2x" /> <p dir="auto">To work around this, we just need to make a small change to steem-python's METADATA file. I've uploaded a patched version to Github to make things easy. Clone the repository, back up your METADATA file, then copy the new one over the old, by running the following commands in the terminal: <pre><code>cd /projects git clone https://github.com/scottyeager/steem-python-setup.git mv /home/user/miniconda3/lib/python3.6/site-packages/steem-0.18.103.dist-info/METADATA /home/user/miniconda3/lib/python3.6/site-packages/steem-0.18.103.dist-info/METADATA.bak cp /projects/steem-python-setup/METADATA /home/user/miniconda3/lib/python3.6/site-packages/steem-0.18.103.dist-info/METADATA <p dir="auto"><br /><br /> Note that this may not be necessary, if steem-python is updated at some point in the future. Try running <code>steempy to see if there's a problem. <h2>Set Node <p dir="auto">The default nodes inlcuded with steem-python are no longer active. You can find the closest public nodes using <a href="http://geo.steem.pl/" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">geo.steem.pl. Then use steempy to set the node of your choice. For example, the Steemit API node over https: <pre><code>steempy set node https://api.steemit.com:443 <h2>Have some fun <p dir="auto">Now we can launch python and play with the library a bit. <pre><code>python >>> from steem import Steem >>> s = Steem() >>> s.get_account('ned')['sbd_balance'] '5750.351 SBD' >>> s.get_feed_entries('ned', 0, 5) [{'author': 'ezzy', 'permlink': 'adventures-of-a-young-stallion-not', 'reblog_by': [], 'reblog_o tside-my-kitchen-window', 'reblog_by': [], 'reblog_on': '1970-01-01T00:00:00', 'entry_id': 34072 {'author': 'dreamrafa', 'permlink': 'concurso-disena-mi-logo-semana-3-desing-my-logo-contest', blog_by': [], 'reblog_on': '1970-01-01T00:00:00', 'entry_id': 34069}] <p dir="auto"><br /><br /> I hope that's sparked your imagination a bit about how it's possible to interact with the Steem blockchain using code. There's much more we could do, including setting up our account to do voting and other actions that require authentication. Check out the <a href="https://steem.readthedocs.io/en/latest/steem.html#steem-your-starting-point" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">documentation for steem-python to get a complete list of commands and much more information about the library. <p dir="auto">The goal of this guide was to make it possible for anyone to start toying with a little bit of Python to interact with Steem. How did it go? Is anything broken or confusing? Let me know in the comments.
Sort:  

This post received a 2.100 SBD (60.77%) upvote from @upvotewhale thanks to @scottyeager! For more information, check out my profile!

Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.Congratulations! This post has been upvoted from the communal account, @minnowsupport, by scott from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.