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?
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.
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
nodelist = NodeList()
nodelist.update_nodes()
hive = Hive()
print()
print ('Please input a Hive username:')
acc = str(input())
account = Account(acc, blockchain_instance=hive)
print()
print("accounts muting", acc, ":")
print('\n'.join(map(str,account.get_muters(raw_name_list=True, limit=100))))
print()
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!
All pictures/screenshots taken by myself or @mrsbozz unless otherwise sourced