create account

A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library by l0k1

View this thread on: hive.blogpeakd.comecency.com
· @l0k1 · (edited)
$0.55
A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library
<div class="pull-left"><h1>I</h1></div> <br />had been having a bit of trouble trying to get the python steem library to work, but I have made a breakthrough. I have also learned a couple of neat python tricks for finding out things about libraries you have imported what is inside them and even their documentation (it even is displayed in a pager so you can browse it).

Here is the code that will print out the data of each new block as it comes in:

    #!/usr/bin/python3
    import steem
    from pprint import pprint

    st = steem.blockchain.Blockchain ( )

    for a in st.blocks():
        pprint(a)

You can browse the help within the python shell like so:

     ✘ loki@vaioe  ~  python3
    Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
    [GCC 4.8.4] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import steem
    >>> help (steem)
    
    >>> help (steem.blockchain)

In the first you see a list of all the submodules, and then you can add that with a '.' between and get more info.

## Update:

This was what I am working towards, now I can grab the current data, so I can process it and generate something from it:

    #!/usr/bin/python3
    import requests
    import json
    
    r = requests.post ( 'https://node.steem.ws', data = '{"id":8,"method":"get_witnesses_by_vote","params":["","100"]}' )
    output = json.loads ( r.text )
    print ( output )

The output is a bit different to using curl to make the same request:

    curl https://node.steem.ws --data '{"id":8,"method":"get_witnesses_by_vote","params":["","100"]}'

But the content is the same otherwise. 

This particular function is missing from @xeroc's steem (formerly piston) library, this is why I have had to learn how to write the requests. This site helped a lot: 

<a href='http://steemroll.io/api-explorer/#method=get_witnesses_by_vote&params=["","100"]'>http://steemroll.io/api-explorer/#method=get_witnesses_by_vote&params=["","100"]</a>

Yes, that is the same query but through the api explorer. Nice huh?

<div class="pull-right">😎</div><br /><hr />

<center><code>We can't code here! This is Whale country!</code></center>
<div class="pull-left"><a href="https://steemit.com/@l0k1"><img src="http://s20.postimg.org/igf27v79p/signature_new_small.png" /></a></div>

<h2>Vote #1 <code>l0k1</code></h2><sub>Go to <a href="https://steemit.com/~witnesses">steemit.com/~witnesses</a> to cast your vote by typing <code>l0k1</code> into the text entry at the bottom of the leaderboard.</sub>

<sub>(note, my username is spelled <code>El Zero Kay One</code> or <code>Lima Zero Kilo One</code>, all lower case)</sub>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 102 others
properties (23)
authorl0k1
permlinka-python-script-that-streams-the-new-blocks-in-json-format-and-how-to-find-full-documentation-for-the-python-steem-library
categorysteem
json_metadata{"tags":["steem","python","piston","coding"],"image":["http://s20.postimg.org/igf27v79p/signature_new_small.png"],"links":["http://steemroll.io/api-explorer/#method=get_witnesses_by_vote&params=[\"\",\"100\"]","https://steemit.com/@l0k1","https://steemit.com/~witnesses"],"app":"steemit/0.1","format":"markdown","users":["xeroc"]}
created2017-03-08 07:53:42
last_update2017-03-08 09:54:51
depth0
children8
last_payout2017-04-08 09:28:30
cashout_time1969-12-31 23:59:59
total_payout_value0.484 HBD
curator_payout_value0.070 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,663
author_reputation94,800,257,230,993
root_title"A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,670,913
net_rshares7,426,409,166,275
author_curate_reward""
vote details (166)
@dragosroua ·
Nifty! :) I just saw the `We can't code here` thing and I had to agree completely. :)
👍  
properties (23)
authordragosroua
permlinkre-l0k1-a-python-script-that-streams-the-new-blocks-in-json-format-and-how-to-find-full-documentation-for-the-python-steem-library-20170308t080638416z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2017-03-08 08:06:39
last_update2017-03-08 08:06:39
depth1
children7
last_payout2017-04-08 09:28:30
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_length85
author_reputation372,798,229,806,288
root_title"A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,670,951
net_rshares193,414,002,934
author_curate_reward""
vote details (1)
@l0k1 ·
I will be publishing soon the info on how to bypass piston because it is missing some vital bit of code that stops it running (and you can't set default_author with it). I dug back into my old posts and found that I had already partly worked out this problem and I have gone further now, setting a specified RPC node to connect to. The code looks  like this:

     st = Steem ( wif = 'aoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoeuaoe', node = 'wss://node.steem.ws')

This sets the account that it requires to have at least one set, that lets you do broadcasts (so you could use a posting key here rather than master or active, possibly even memo only for read only functions). I think it needs this for the `custom_json` function in `Steem`, I am writing a script to grab the data of the active witnesses so I can process the data in the output.
properties (22)
authorl0k1
permlinkre-dragosroua-re-l0k1-a-python-script-that-streams-the-new-blocks-in-json-format-and-how-to-find-full-documentation-for-the-python-steem-library-20170308t085854876z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2017-03-08 08:58:57
last_update2017-03-08 08:58:57
depth2
children6
last_payout2017-04-08 09:28:30
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_length848
author_reputation94,800,257,230,993
root_title"A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,671,158
net_rshares0
@dragosroua ·
Hmmm, I don't think it's because of Piston, in this case. If different nodes are allowing you to do different things, it must be from the nodes themselves, not from Piston. 

My guess is that node.steem.ws runs a broader set of APIs, possibly some related to accounts (don't have time to dig to see which plugins are related to accounts, but I know it was a discussion on github about this). That means you can set up your own Steem seed node, enable the plugins related to accounts, and interact with it instead of sending transactions to node.steem.ws (and increasing the load on it). If you configure your seed node properly it will take care of all the necessary operations, including broadcasting transactions, etc.

Hope it helps.
👍  
properties (23)
authordragosroua
permlinkre-l0k1-re-dragosroua-re-l0k1-a-python-script-that-streams-the-new-blocks-in-json-format-and-how-to-find-full-documentation-for-the-python-steem-library-20170308t092906608z
categorysteem
json_metadata{"tags":["steem"],"app":"steemit/0.1"}
created2017-03-08 09:29:06
last_update2017-03-08 09:29:06
depth3
children5
last_payout2017-04-08 09:28:30
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_length736
author_reputation372,798,229,806,288
root_title"A python script that streams the new blocks in JSON format - and how to find full documentation for the python steem library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,671,285
net_rshares189,528,437,001
author_curate_reward""
vote details (1)