I.T. Spices The LINUX Way

Python In The Shell: The STEEMIT Ecosystem – Post #97

THE BEAUTY OF PYTHON AND LINUX SHELL COMBINED

In continuation as per the previous post here:

https://steemit.com/blockchain/@lightingmacsteem/6spst7-i-t-spices-the-linux-way

And in finishing our discussion as per the short python code below:

1 ###FIND THE LINE NUMBER OF THE BLOCK_ID IN THE INSERTFILE
2 if maxid != 0:
3   findthis = ('"block_id": "' + blockid[1] + '"')
4   ccc = ("grep -m1 -n '" + findthis + "' " + insertfile + " | cut --delimiter=':' -f1")   
5   line = int((os.popen(ccc).read()).strip()) + 1
6   lastline = int(line) + int(299999)
7   endline = int(lastline) + 1
8 else:
9   line = int(1)
10  lastline = line + int(299999)
11  endline = int(lastline) + 1


What If The Database Is Still Empty

8 else:
9   line = int(1)
10  lastline = line + int(299999)
11  endline = int(lastline) + 1

The last four lines above can be best laid out if discussed in one go.

Line 8 means that if the maxid line on line 2 is not true then this is where and what python will go and execute. We are making sure that the code does not go astray here by explicitly telling it what to do if in case. Again, error handling at its very roots will make your python program much better and manageable.

Since these last lines are for the instance that the database is still empty, then line 9 (the very first line to process) is of course line number 1.

We add the count 299999 lines and we got a total of 300 thousand lines, line 10 took care of this number as decided by me the coder. Python is very efficient, but it needs our guidance.

Line 11 defines the very last line, and whatever the number as a result is not included in the processing. We tell python at this point that if you reach this line number of JSON blockchain record, you have to stop. We have to stop at certain intervals of course if what we want to achieve is finishing off millions of lines, no need to do this if we are just processing hundreds of lines.

Overall and in following the IF statement, we told python what things to do if the database have records already, and just in case it is still empty, we also tell it to do another.


Use Tools To The Best Of Your Purpose

In my more than twenty plus years in this field of I.T., I learned that the tools for our disposal can be used for a lot of purposes and dumminess, much like when one uses a screwdriver to drive a nail instead of a hammer.

In these lines, I have demonstrated that python is best complimented by the linux shell “at certain instances”, not all and I have to be very clear about this. Mix N’ Match may be good, but not at all times.

Stay glued in there, we will reach a point in the program where we used python purely to manipulate and query the database.


“Be Away, Your Words Are Piercing Me, Your Life So Melting… Your Person So Different, It Reminds Me Of Who I Am Not In Front Of The Mirror…...”

Sort:  

Congratulations @lightingmacsteem! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 600 upvotes. Your next target is to reach 700 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Trick or Treat - Publish your scariest halloween story and win a new badge
SteemitBoard notifications improved

Support SteemitBoard's project! Vote for its witness and get one more award!