Python for STEEM: How to beem

in #busy5 years ago (edited)

This is meant as the first part to a series of tutorials.
The goal is to produce a hands-on guide for people who want to jump straight into developing tools for STEEM.

In this part, I will try to guide you through the process of installing beem.
beem is a Python library for STEEM and is based on steem-python, which is based on piston-lib.
While steem-python is the official lib, I chose beem, because it is updated more frequently. ( At this time, the last update to steem-python is 9 months old)

While it is possible to install Python and beem on Windows, I will start by setting up a virtual machine, which I will install Linux on.
In my opinion, this has multiple benefits, the main one being that it will encapsulate your development environment; Whatever abomination you code up, it will not be able to wreck your main operating system - In the worst case, you can stop the virtual machine and start it again.

I believe this method to be the easiest for most people.
If you want to install beem on a different system, this is not the right guide for you. If you can figure it out on your own, you can jump a chapter ahead.

VMware

There is a free version of VMware, which is ideal for our purposes:
https://www.vmware.com/products/workstation-player.html
Make sure to download the Workstation Player, as only that is free to use.

Install this, make sure to uncheck the regular updates nonsense.

Ubuntu

I will go with Ubuntu 18.04.3 LTS, as that seems to be the most popular choice at the moment.
https://ubuntu.com/download/desktop

Open VMware, create a new virtual machine using a Ubuntu 18.04.3 LTS image.

  • 10 GB HDD, 2 GB RAM is enough, perhaps less
  • You do not need VMware tools
  • Set a password. I bricked my first Linux ever, by trying to set it up with a blank password.
    It does not have to be especially secure.

beem

If you are new to Linux - don't panic ! I don't get it either.
Before doing anything, remove Amazon from you 'Favourites' menu.
If your keyboard layout is not English, you need to go to 'Region and Languages' and add a new keyboard layout, which makes no sense, and is very confusing.

  • ctrl+alt+t opens a new terminal.
  • sudo apt-get update
    Apparently, this will update your system.
    It is always recommended. Once you have a running bot for STEEM, this might completely ruin your day, though.

Note:
ctrl+c, ctrl+v do not work like they do in Windows.
This is just to confuse everybody.


  • sudo apt-get install build-essential libssl-dev python-dev
  • yes
  • sudo apt install python3-pip
  • yes
  • sudo pip3 install beem
  • yes

Test

The easiest way to test, if it went right, is to:
beempy --help
beempy is a wallet that is built on beem.
If you see a list of help topics, you have successfully set up beem.

To test your first own script, create a new file:
gedit beemtest.py
This will open a text editor.

from beem.blockchain import Blockchain
blockchain = Blockchain()
print(blockchain.get_current_block_num())

paste the above 3 lines of code and save the file.
python3 beemtest.py
This will execute your script and should print the current head-block number on your screen.

Congratulations

If it did not work as intended, comment below.

I hope @flipstar gets to test this.
Also mentioning @revisesociology for good measure.

-> Part 2

Sort:  

ctrl+c, ctrl+v do not work like they do in Windows

Just in case you don't know:
In Linux terminal it works with ctrl+shift+c and ctrl+shift+v

No, I didn't know.

To make matters worse: It works inside gedit.

Good stuff. Wanted to get started with that anyways. Now I'm taking the lazy route instead of tinkering myself :)
!BEER

Posted using Partiko Android

How to !BEER !
:)

Command accepted!



Hey @felixxx, here is a little bit of BEER for you. Enjoy it!

I am more of a virtualbox user myself, but I also run Ubuntu 18.04 on my primary desktop computer anyways.

Very interested in where you take these posts as I would like to write some Python code to track and log my Steem data using some of the metrics that I manually get from steemworld.org and steemitboard.com currently.

You might also want to add a STEM tag to get some rewards from that community.

I did not think of the STEM tag. I used up the 5 tags that busy.org allows me to use ...

Depending on what you want to do, I could just work on that.

Which data do you need, how do you want it exported ?

edit: I wanted to take this all the way to SMT creation ...

I have tried reading the beem documentation and either do not understand enough Python to properly use it, or some of the stuff I want is not directly callable.

I think I replied to my comment to answer your original question so I do not know if you get notified.

The documentation isn't great.
If it is part of steemworld.org, it is most likely directly callable.

In the next part, I was just going to look at a full block and how STEEM stores data.

Some parts further, I will explain how I read the source code to look at every function.

In the end, this tutorial should enable you to do all the things you mentioned in the other comment.

Thanks that sounds exactly the kind of information I am looking for.

For now things like posts, comments, votes(received-given), SP vested, SP delegated and reputation. Eventually I would like to be able to run queries like who I have voted for and who has voted for me. I know there are many different web pages to get most of this, but as I am learning Python I would like the experience of writing the code myself.

Nice!
Now you only need to learn python!
@tipu curate ;)

While in many ways I am still a beginner, I can work with it alright :(

Feel you, my skills are definetely worse ^^

Ich danke dir vielmals.

Hey I'll look into this at some point - bit busy with work next few days but I'll check back for sure!

Posted using Partiko Android



Hey @felixxx, here is a little bit of BEER for you. Enjoy it!

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98085.38
ETH 3350.61
USDT 1.00
SBD 3.03