Python Programming with Piston: How to set a login key using Python (not the piston executable)

in #development8 years ago (edited)

I am writing a python3/gtk+-3.0 app and I will be making posts as I find resolutions to issues I run into as I seek to do things with the piston library that are not yet documented. @xeroc, or others who are interested, do follow my blog and I will make posts tagged with #piston that you can pick through to gather the information. I know that others with knowledge of Python who want to write Steem based apps, simple examples being a Steem wallet using a Qt interface, or a complete Steem viewer (Mine will be targeting Gtk+-3.0) can use this information to build such an application.

I am working from the excellent piston library that you can install using pip3. You can find instructions for how to do this from @xeroc's blog, and there is the beginnings of documentation available from locations you can find on his blog.

In the example below, in order to perform a check to certify that a key is valid, a second import has to be done to acquire the calls and exceptions from the piston.wallet code. The example below I am using a data store backed from dconf to store the WIF (login key) code. The script attempts to create a Steem object using this key, and if the WIF is invalid, where you would put the code you run when the test is successful I have a simple print command, and conversely, if it fails, there is another print command that notifies you of this case also.

Note that there is an additional import that needs to be done that creates a namespace for the piston.wallet codebase.

from piston.steem import Steem
from piston import wallet as Wallet
# ...
    def test_login (self, window, settings):
        wif = settings.get_string("wif")
        try:
            steem_account = Steem(wif=wif)
        except Wallet.InvalidWifError:
            print ("invalid wif")
        else:
            print ("wif accepted")
Sort:  

By the way, I like to make it a habit that whenever someone votes for a post I make, I follow them, so I can see what people who like my stuff are also posting, as a way to help me find like minded people on here. I don't do it all the time but certainly if you make an insightful comment on my posts, I will probably follow you as well. I think it is a courtesy that will eventually become part of Steemit etiquette.

Maybe the developers intended this only to be a blogging platform, but this alone won't bring in the userbase, people want a facebook killer. A lot of these features have nothing whatsoever to do with the blockchain at all.

I've had a crazy busy time since making this post, the latest bit of disruption was the installation of the amdgpu driver left me high and dry with no computer to access the internet with for 24 hours.

After @xeroc told me there is a load-balanced network of RPC endpoints, it occurred to me that in fact I was free to switch my platform to a much wider range of possible platforms, for example, a favourite of mine, Vala. But circumstance has conspired repeatedly now to push me towards Python, and even with access to RPC endpoints, I don't get the benefit of a complete friendly API that hides the complicated parts of setting up these RPC connections. This would end up being a lot of unproductive work and probably at least for some time yet, would not be used by anyone.

I am dog tired at the moment, so I'm not going to do anything this evening, but I think my next post on this subject will be about how to set the RPC to use the https://steem.ws/ endpoints. According to that site, the connection string is wss://node.steem.ws - the default in piston is (I guess with the URL prefix added): wss://this.piston.rocks

Anyway, so hopefully I will be posting more posts like this in the future really soon, every time I figure out something not as yet documented.

For sure some nice little code there man, I am directly setting ym wif so it doesnt quite work for me but thats ok, I know it works cause I was able to do a comment with it the other day, have you by any chance seen anything about how to get access to ones followers/following list using the steem.piston api?

There apparently is information about this, I found a post that I replied to about it.

https://steemit.com/steem/@l0k1/followers-and-following-is-this-on-the-blockchain-or-is-it-only-implemented-by-the-webpage#@l0k1/re-raymonjohnstone-re-l0k1-followers-and-following-is-this-on-the-blockchain-or-is-it-only-implemented-by-the-webpage-20160821t204208104z

https://github.com/inertia186/radiator << this apparently has a ruby-based interface for checking follower/followed stats. I will be checking this out to implement the same function in Python.

oh, look, YOU found it.

followers/following is not on the blockchain, afaik. that's in a separate database on the webserver.

I could be wrong but I believe this is exactly why to extend the utility of the Steem platform, it will require more distributed databases/blockchains to be implemented. I also think that was an intentional design feature from the Steem devs. They want to make a whole ecosystem out of this. This site is just the baseline.

NOTE: This key check will only work if you use the ones that you have to manually 'show private key'

Click 'login to show' here

Depending on what you want to do, you will need to unhide the ones you want from this list:

how to call test_login in the above example ?

Hi there, I was using your guidelines and I find them very helpful, but I keep getting stuck. I imported the library but it still gives me a syntax error on every operation I am trying to execute. Is there something I am doing wrong? Are those codes only to implement in the terminal directly maybe?

from piston.steem import steem
piston categories --limit 10

then I execute this file by going to the terminal and executing

python3 <path>

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.029
BTC 58522.98
ETH 3089.61
USDT 1.00
SBD 2.41