create account

Let's build Bots for STEEM - Part 03: Install steem-python on Ubuntu 17.10 by botsultant

View this thread on: hive.blogpeakd.comecency.com
· @botsultant · (edited)
Let's build Bots for STEEM - Part 03: Install steem-python on Ubuntu 17.10
# Hi Steemians, let's build BOTS!
####
On this blog I want to document my progress in implementing bots for the STEEM blockchain. 

https://steemitimages.com/DQmYBEXnPDCks41VWPfQr5HAfE6kfMoH6NYArDbrkzND7pT/robots-764951_1280.png
<center>Image Source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/</center>

In [my last post I tried to install steem-python on Ubuntu 16.04](https://steemit.com/steem/@botsultant/let-s-build-bots-for-steem-part-02-i-tried-to-install-steem-python-on-ubuntu-16-04-but-i-failed), but I failed. 

## Upgrade to Ubuntu 17.10
####
Instead I tried to upgrade to 17.04, but this was also not possible because an python library was missed. I contacted the privex supported and asked them to install a clean 17.04. instead. After some hours my new server was ready. Awesome job, @privex!

Since [@felixxx's installation guide](https://steemit.com/steem-python/@felixxx/learning-python-with-felixxx-1-setup-and-first-script) is based on Ubuntu 17.10, and my system was running 17.04, I first upgraded to 17.10. Just type 

`do-release-upgrade`

and answer every question with **yes** or select the default option.

## Installation ala @felixxx
####
I installed steem-python according to @felixxx's guide, but only needed to change the order of the commands. The scrypt installation requires some aes headers, so install **libssl-dev** infront of **scrypt**.

```
sudo apt install python3-pip
sudo apt-get install libssl-dev
pip3 install setuptools
pip3 install scrypt
pip3 install wheel
pip3 install pytest
pip3 install steem
````

## The first script from felixxx
####
I'm a lazy coder and just copy pasted @felixxx's first script and started it ...
```
from steem.blockchain import Blockchain
from steem.post import Post
b = Blockchain()
s = map(Post, b.stream(filter_by=['comment']))

for post in s:
    if post.is_main_post():
        print('https://steemit.com/tag/@' + post['author'] + '/' + post['permlink'])
```
####
and it failed.

```
$ python3 firstscrypt.py
WARNING:urllib3.connectionpool:Retrying (Retry(total=19, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ff6689c1208>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /
WARNING:urllib3.connectionpool:Retrying (Retry(total=18, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ff6689c12e8>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /
WARNING:urllib3.connectionpool:Retrying (Retry(total=17, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ff6689c1358>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /
WARNING:urllib3.connectionpool:Retrying (Retry(total=16, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ff6689c1470>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /
```

## Set a steemd node
####
It failed because [steemit.com disabled their legacy steemd node](https://steemit.com/steemitdev/@steemitdev/last-chance-to-update-steemd-steemit-com-will-be-retired-on-january-6) around 2 weeks ago.

It's very easy to set an alternative steemd node in steem-python. I usually use these code fragments, but I'm not sure if this is the most efficient and secure option. 

```
from steem.blockchain import Blockchain
from steem.post import Post
from steem.instance import set_shared_steemd_instance
from steem.steemd import Steemd
from steem.steem import Steem

# steemd_nodes = ['https://api.steemit.com']
steemd_nodes = ['https://steemd.pevo.science']

set_shared_steemd_instance(Steemd(nodes=steemd_nodes))
steem = Steem()
b = Blockchain()
s = map(Post, b.stream(filter_by=['comment']))

for post in s:
    if post.is_main_post():
        print('https://steemit.com/tag/@' + post['author'] + '/' + post['permlink'])
```
####
I first tried the new node from steemit.inc (https://api.steemit.com), but I got no results. Later I switched to @pharesim's public node (https://steemd.pevo.science), and the script worked.

```
$ python3 firstscript.py 
https://steemit.com/tag/@rslabbert/death-of-my-dishwasher
https://steemit.com/tag/@rahmats/the-beauty-of-heaven-in-the-afternoon-when-the-sun-begins-to-disappear-13fec1c539d8c
https://steemit.com/tag/@lawyergt/qxbus
https://steemit.com/tag/@lgh950927/k-pop
https://steemit.com/tag/@cityslicker/wanna-have-some--2018-01-15-11-27-45
https://steemit.com/tag/@rnb/does-coffee-kill-your-heart-and-bacon-is-more-harmful-than-cigarettes
```

## Next steps
####
In my next tutorial I plan to start interactions between steem-python and discord. Stay tuned.
👍  ,
properties (23)
authorbotsultant
permlinklet-s-build-bots-for-steem-part-03-install-steem-python-on-ubuntu-17-10
categorysteem
json_metadata{"tags":["steem","steemdev","utopian-io","python","ubuntu"],"users":["privex","felixxx","pharesim"],"image":["https://steemitimages.com/DQmYBEXnPDCks41VWPfQr5HAfE6kfMoH6NYArDbrkzND7pT/robots-764951_1280.png"],"links":["https://pixabay.com/de/roboter-computer-bots-charakter-764951/","https://steemit.com/steem/@botsultant/let-s-build-bots-for-steem-part-02-i-tried-to-install-steem-python-on-ubuntu-16-04-but-i-failed","https://steemit.com/steem-python/@felixxx/learning-python-with-felixxx-1-setup-and-first-script","https://steemit.com/steemitdev/@steemitdev/last-chance-to-update-steemd-steemit-com-will-be-retired-on-january-6","https://api.steemit.com","https://steemd.pevo.science"],"app":"steemit/0.1","format":"markdown"}
created2018-01-15 11:35:39
last_update2018-01-15 11:43:48
depth0
children1
last_payout2018-01-22 11:35:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,971
author_reputation113,201,096,904
root_title"Let's build Bots for STEEM - Part 03: Install steem-python on Ubuntu 17.10"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,681,625
net_rshares1,467,916,634
author_curate_reward""
vote details (2)
@rodthrower18 ·
Looking forward to the continued parts of this project. Who would've ever thought I'd actually WANT to learn a new language after being out of the game for 15yrs. Thanks for this!
properties (22)
authorrodthrower18
permlinkre-botsultant-let-s-build-bots-for-steem-part-03-install-steem-python-on-ubuntu-17-10-20180117t111932899z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2018-01-17 11:19:39
last_update2018-01-17 11:19:39
depth1
children0
last_payout2018-01-24 11:19:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length179
author_reputation104,840,677,951
root_title"Let's build Bots for STEEM - Part 03: Install steem-python on Ubuntu 17.10"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,150,007
net_rshares0