Diving into Python: You can teach an old dog new tricks!

avatar

IMG_20220215_072505.jpg


Many moons ago I was a university student majoring in Computer Information Systems. Back then, things weren't as segmented as they are today. You either majored in Computer Science which was mostly programming, or Computer Information Systems which was basically everything else.

These days, students have many more options, you can specialize in cyber security, networking, servers, you name it, there is probably a course track for it.

Although I didn't go into Computer Science, I still had to do a bit of programming to satisfy the courses for my Bachelor's Degree. We mostly worked with C++ on a Unix terminal with tools like PICO, VI, and PINE (for email). We also dabbled a bit in SQL, COBOL, Visual BASIC, and Assembly. I was never the best at it, but I passed my classes and then I kind of put it on the shelf and forgot about it.

Sure, I did stuff with HTML over the years, but who didn't hard code their first webpage in a notepad file right?

image.png


When @slobberchops and @steevc started poking around with Hive using Python and Beem, it piqued my interest, but not enough for me to actually take any action and start learning Python. At least not right away. Clearly I eventually did, otherwise I wouldn't be writing this post.

My first issue was deciding where to install it. I tried installing some of the Windows versions of Python, but I couldn't get Beem to install properly. It had a bunch of dependencies or something that weren't very straightforward to resolve in Windows.

Instead, I decided to spin up a virtual machine on one of my servers here at work. I installed Ubuntu Desktop 22 and I was able to get Python and Beem installed relatively easily.

You see, a while ago I had an account mute me on Hive. I was a bit taken aback by that, so it got me thinking I wonder how many other people have me on mute. As I explained in my post last week, it's possible there is already an easy way to do this, but I thought it might be a good opening for me to try learning Python.

With Python and Beem installed, I started working on making my program. Oh yeah, I should also point out, I got tired of the copy and paste restrictions between my desktop and my VM Host, so I ended up enabling SSH on my Ubuntu machine and I basically just do everything via the command line.

That means I am using Nano to write up my files. It's basically just a newer version of Pico. Not as powerful as VI, but in my opinion much more user friendly.

I ran into some snags with syntax that had me thinking something was wrong with my install, but luckily the legendary Marky helped me out with that in the Bro Discord.

image.png


I started with a simple "Hello World" program, then a greater than/less than program that @slobberchops had to help me a bit with. I was defining my variables incorrectly and it was leading to some crazy results.

From there I started working in Beem. I did a simple program that showed what version of Hive I was running. Then I wrote some code that showed what my HBD balance was. I thought it might be cool to be able to pick who you wanted to see account information for without editing the code, so I added a prompt where you can enter a username and it provides the appropriate output.

At that point, I figured I was ready, so I started working with the account.get muters function in the Beem library.

It worked for the account I had entered, but I wanted to find that info for any account. So I added the code to be able to prompt for user input.

Eventually, I had a program I was proud of and you can find it on my Github page here.

It's really quite simple, but I am proud of it for my first real go at programming in 25+ years. You have to start somewhere right?

Let's have a look:

from beem.account import Account
from beem import Hive
from beem.nodelist import NodeList

  • This is basically just pulling in the pieces we are going to be working with.

nodelist = NodeList()
nodelist.update_nodes()
hive = Hive()

  • Then we set up some easier to type variables to make the rest of the code easier.

print()
print ('Please input a Hive username:')
acc = str(input())
account = Account(acc, blockchain_instance=hive)
print()

  • This is the part that prompts for a user name. We ask for the input, then we accept that input as the acc variable. Finally, we tie that user input to an actual account on the Hive blockchain.

print("accounts muting", acc, ":")
print('\n'.join(map(str,account.get_muters(raw_name_list=True, limit=100))))
print()

  • The rest is pretty easy, we have the system print a line of text saying "Accounts Muting Bozz" or whatever input you enter at the beginning. Then, a quick line of text to output the accounts that are muting the input account.

It was originally outputting the accounts as a list separated by commas. I decided I wanted it to list each account on a separate line in a vertical format, so I added the \n .join command to make it more visually pleasing.

I've recently discovered that Beem has kind of been defunct for a while and though it still works, it doesn't get updated. There is another library called LightHive that does a lot of the same things. I tried it out and what took me about 15 lines of code to do, I was able to accomplish in 5 with LightHive. I think it is still a work in progress, but so far it seems pretty cool.

So there you go, my first dive into Python programming. It's pretty cool so far and when I have more time I hope to dig into it a bit more. @slobberchops just made this great post yesterday about how he is using Python with Splinterlands.

Awesome stuff!


Sports Talk Social - @bozz.sports


TEAMUSAhive_footer_bozz.jpg


All pictures/screenshots taken by myself or @mrsbozz unless otherwise sourced



0
0
0.000
43 comments
avatar

Code words can be so exciting, though I am not fully learned in that aspect. I'd admit that the little code I know is because of Hive, which I find beautiful.

I don't really understand much of what you've said about how you use codes, but I find them thrilling. It is like seeing a spy movie. Lol.

Thanks for yesterday. I truly appreciate you.

0
0
0.000
avatar

It's definitely not for everyone. I'm still learning myself. Thanks for stopping by.

0
0
0.000
avatar

That's very right. You are welcome 😊.

0
0
0.000
avatar

I must try this stuff out. I’m a software engineer and studied that as my degree back in the day. The one language I never use though, is Python! Easy to learn though.

0
0
0.000
avatar

Oh, you should have no problem. If I can do it anyone can do it. I am so rusty that I am surprised I was still able to string anything together into something that worked.

0
0
0.000
avatar

Sometimes these skills never go forgotten 😀

0
0
0.000
avatar

I love the way you've shoved all the crap to the sides in that first picture, very organised!

BEER

0
0
0.000
avatar

My office is a hot mess for sure. It's disgusting, but I can never seem to get it clean.

0
0
0.000
avatar

Years ago did A+ through American Based training course over here, yup DOS, later some SQL to tweak a few changes within a software used in corporate world, onto some web builds, now not touched in some time with too many interruptions breaking thought.

Great to see you tackling once again it takes patience, well worthwhile to have one or two basics to help you through, well done!

0
0
0.000
avatar

I studied for my A+, but I never got around to taking it. I kind of wish I had sometimes.

0
0
0.000
avatar

I did it for the Y2K change. Purchasing new systems in offices required knowledge, able to substantiate cost involved from change over, know more than simply the workings most see, always need to delve a little deeper. My curiosity I suppose.

0
0
0.000
avatar

Ah yes, I did a lot of work in different places during that period as well. It was an interesting time!

0
0
0.000
avatar

The days where you grew learning on the go, too many changes now to keep up, I gave up, know what I know, still dip in every so often just for fun.

0
0
0.000
avatar

That's awesome. I took some C and Java courses in college, and after finishing those subjects I decided I don't want to code. Seeing how coding seems to be easier now [less lines of code] is really nice. I don't know if I will be trying to code again, but it is nice to know that the experience is better.

0
0
0.000
avatar

Plus the AI these days can do a lot of the code for you too. I haven't tried it yet, but I have heard it is pretty impressive. I don't think I could get away with doing coding for a living, but it's fun to play around with.

0
0
0.000
avatar

Great work, you are motivating me to power up my python again and use with Hive. Im not sure if python or SQL first though.

0
0
0.000
avatar

I think they are both great options. I want to mess around with SQL a bit more too.

0
0
0.000
avatar
(Edited)

Python really intrigues me. Planning to study this one of this days. !PGM

0
0
0.000
avatar

Sent 0.1 PGM - 0.1 LVL- 1 STARBITS - 0.05 DEC - 1 SBT - 0.1 THG - 0.000001 SQM - 0.1 BUDS - 0.01 WOO - 0.005 SCRAP tokens

remaining commands 5

BUY AND STAKE THE PGM TO SEND A LOT OF TOKENS!

The tokens that the command sends are: 0.1 PGM-0.1 LVL-0.1 THGAMING-0.05 DEC-15 SBT-1 STARBITS-[0.00000001 BTC (SWAP.BTC) only if you have 2500 PGM in stake or more ]

5000 PGM IN STAKE = 2x rewards!

image.png
Discord image.png

Support the curation account @ pgm-curator with a delegation 10 HP - 50 HP - 100 HP - 500 HP - 1000 HP

Get potential votes from @ pgm-curator by paying in PGM, here is a guide

I'm a bot, if you want a hand ask @ zottone444


0
0
0.000
avatar

One of the old dogs here. Want to learn new tricks and make life more exciting 😁 !PGM

0
0
0.000
avatar

Sent 0.1 PGM - 0.1 LVL- 1 STARBITS - 0.05 DEC - 1 SBT - 0.1 THG - 0.000001 SQM - 0.1 BUDS - 0.01 WOO - 0.005 SCRAP tokens

remaining commands 4

BUY AND STAKE THE PGM TO SEND A LOT OF TOKENS!

The tokens that the command sends are: 0.1 PGM-0.1 LVL-0.1 THGAMING-0.05 DEC-15 SBT-1 STARBITS-[0.00000001 BTC (SWAP.BTC) only if you have 2500 PGM in stake or more ]

5000 PGM IN STAKE = 2x rewards!

image.png
Discord image.png

Support the curation account @ pgm-curator with a delegation 10 HP - 50 HP - 100 HP - 500 HP - 1000 HP

Get potential votes from @ pgm-curator by paying in PGM, here is a guide

I'm a bot, if you want a hand ask @ zottone444


0
0
0.000
avatar

I kinda ran through the same process two years ago. You can try google codelab as a test environment. It has a python notebook format but lets you install the libraries and you can share your files with anyone.

0
0
0.000
avatar

Oh, that is cool. I was looking for something like that, but I honestly don't mind using the Ubuntu VM. It works really well and I can access it pretty easily.

0
0
0.000
avatar
(Edited)

I get to use Python at work, so I have picked up a few tricks for that. It is really powerful, but you can use simple structures for this sort of thing. A lot depends on the libraries you have. beem is pretty good, but I need to look into LightHive as we need something that is supported. If you know SQL then @hivesql can do a lot.

BTW I just tried your script. I found one bug. It seems a lot of people mute me :)

0
0
0.000
avatar

Haha, yeah, you do have more than some of us. I noticed that too! That is cool that you do so much with it at work. I wish I had to use it more, then I might be better at it. I enjoyed the SQL class I took but I have forgotten a lot of it. I might need to checkout @hivesql.

0
0
0.000
avatar

You do need to use these tools to keep your skills up. There are other languages I used to use, but I'm rusty with those now.

0
0
0.000
avatar
(Edited)

Hmm at my university (Ball State), Computer Science was very little programing and was mostly theory. We did have to learn enough assembly and machine language to be able to write a complete C++ complier our final project. Hmm... that was actually learning machine language mainly... had to first change the machine language to assembler, then change that to C++. Man, that took me forever to do. I still have it on a Zip disk somewhere (but I no longer have any Zip drives). But anyway it was on us to learn all the code—classes didn't help out in the details. Mostly theory and math. Ugh...all the math. Sounds like you actually got more exposure to programming languages than I did. Nice!

Looks like you have a great setup at work! Wow!! Meanwhile I am working on a tiny little 13" laptop. I'd love to get me four screens!

Edit: No, I'm thinking backwards, aren't I? Sorry, it's late here and my mind isn't working. We changed the code to assembler and then to machine language. I had pages and pages and pages of printouts for all the machine language instructions.

0
0
0.000
avatar

I hated Assembly. It was one of the few college courses I got a C in. I did not enjoy it at all. The only thing I was good at was hash tables in C++. Those came pretty naturally to me.

0
0
0.000
avatar

I think I didn't mind so much because my first programming language when I was about 7 was BASIC on my Commodore 64 (and the tandy's at school. I think we have one Apple ][ as well). So BASIC trained me to be ok with that same kind of format that Assembly used... That said, high level languages like C++ were so much nicer!

0
0
0.000
avatar

I did a lot of BASIC stuff on our Texas Instruments computer that we had. We had an audio tape drive so we could save the programs and load them back up without having to write them all over again. I remember my dad subscribed to a magazine that had different programs in it each month.

0
0
0.000
avatar

I loved those magazines when I was a kid. I spent hours typing those programs in!

0
0
0.000
avatar

That is awesome! I've considered trying it out, but being an old dog the new tricks won't be as easy as they used to be. Way to go, looks like you still got the skills!

0
0
0.000
avatar

Thanks, I appreciate it. It's definitely something that I hope to build upon over the years. I'd love to pull some more useful data.

0
0
0.000
avatar

Coding may be interesting and simple to people like you but it seem hard to me maybe because I'm not good at it, lol
I wish to have an idea abutting it though even though it is little

0
0
0.000
avatar

It took me forever to come up with this idea. Luckily there was a function in place already for it.

0
0
0.000
avatar

Is that your office at work? If so, they don't half give you a lot of screens. Are you sure you're not a security guard?

0
0
0.000
avatar

Yeah, that is my office. I have five screens total. There are times I wish I had more!

0
0
0.000
avatar

Looks good and have fun!

I'm interested with your feedback for both Beem and Lighthive.

0
0
0.000
avatar

I'll have to dig into them more. I already feel like lighthive has been built out a bit more simply for the fact that I can do the same thing in fewer lines of code.

0
0
0.000