Python Libraries: Sending an Argument via the Command Line

in #hive-1635213 years ago

The Random Voter script is still being developed and now sends random votes to over 200 different accounts. If you want to be considered as an addition and you don't write a big pile of dogshit then comment below. I am always looking for good deserving authors.

My surplus accounts, @chops.support, @dismayedworld, @bingbabe, and @wanker all send 100% votes, and if my main account is flush with voting power, adds a further 5% vote to the mix.

Caption.JPG

My memory occasionally drifts back to March 2018, STEEM, and the random vote of @hr1 who I had the pleasure of shaking hands during STEEMFest 3 in Krakow. @hr1 voted people, mostly new people at random, had a massive pile of STEEM and was a kind of saviour to me.

IMG_4565.JPG

...'@hr1 does exist... accompanied with a smiling @detlev, I thought him a myth until I witnessed this sight'...

How cool would it be to be 'another @hr1' and to dish out votes to other struggling HIVE authors who consistently deliver?

I never for one minute thought I would ever be in the position to do so, and @hr1’s algorithm was for new posts, whereas mine is whenever I run the script.


image.png
...'@the hr1 account now sits alone with little HP. How things change'...

What I wanted was the ability to change the @slobberchops vote weight without changing the core script code.

I am familiar with other scripting languages and knew this would be in the form of an argument on the command line.

The way that I learn new functions, methods, or routines is to get examples from the internet. Figure out how they work, and then write them into your code.

Once you have done it, then you have a working example that can then be re-used.

I tried here first and the code kept giving me an error.

no brackets example.JPG

Source

It appears some variants of Python don't require brackets around print statements, whereas Anaconda does. You learn something every day.

print ('Number of arguments:', len(sys.argv), 'arguments.')

Adding the brackets so it would work I was initially confused about the type of property sys.argv was. The len method generally tells us the length and a little homework tells me it’s an array.

egsoutput.jpg

The output from this script now made sense and so I was looking to add a second argument which would be a variable integer containing the vote weight.

Another search brought me the answer, although many other more over-complex solutions were presented to me.

one way.JPG
Source

I like to keep it simple otherwise when looking back at old code I will forget what I did.

It made sense; this line of code if true meant that no parameter was sent on the command line and that the @slobberchops account should vote at a 5% weight.

if len(sys.argv) == 1:

All I needed to do was incorporate this into my script and I could determine the vote weight, and add a little more if I had some to spare.

functioncall_getweights.JPG

This line of code calls the function, sends the account name from a list, and expects two return values.

Unlike some other scripting languages, Python allows the programmer to return more than a single value; most useful!

The function has now been modified to check, in hardcoding terms for the @slobberchops account, intercept anything other than the first argument and utilize it (if it exists).

GetWeights_Func.JPG

To make this a little clearer if the @slobberchops is above a voting power of 87% then it will vote at 5% unless an alternate numeric parameter was sent via the command line

This would be equal to the property found in the sys.argv[1]. Like many other languages, the first element in Python arrays starts at 0.

10% votes.JPG

...'typically I would use an optional argument of '10' to send 10% weight votes instead of 5% during times when I have excess VP'...

The other voting accounts will cease to vote below 75% VP and will always vote at a weight of 100%.

10weight.jpg

I hope this is a little clearer by example. I learned to code without courses, books, exams. Over the years I have found you either have the head for it or you don't.

If this seems complex then you may be the type who would never understand it. I have tried umpteen times to teach other 'techies' the basics of VBScript and failed.

RedLine.png

  • Earn currency while you play brewing virtual beer with CryptoBrewMaster
  • Earn currency while you play and become a global Rock Star with Rising Star


CurieCurator.jpg

Sort:  

Learning python is my dream. Though I am now trying to get c++ for some reason. I have a plan to learn about python.

C sharp developers are in demand in my country. Python devs also demand decent $$$.

After knowing the demand of c and its upgraded version, I had decided to learn it first. I want to go ahead as my plan. I have belief in myself.

So great that you have got to a position where you can emulate hr1! I remember you talking about this mythical voter ... were they real?

The code looks tricky, but then I don't know Python. I like the logic of code, though.

You should have seen @hr1 at Krakow, I know you were there! Any thoughts on a meetup now this COVID rubbish has been swept under the table?

1

Someone who writes every day and could use help is @jacobpeacock

Agreed,.. added thanks.

thank you for adding him

How cool would it be to be 'another @hr1' and to dish out votes to other struggling HIVE authors who consistently deliver?

I think, all curation can make this place collectively better by working together to reward these struggling authors ?

I do what I can, the list is mostly made up of people I don't follow. I can't follow everyone as that would be unmanageable.

you are not fucking human!

Years of pouring over BASIC listings in the derelict Kwiksave canteen brought me here. While being forced to make coffee for Mort, (and trying to poison him), I took in a little more every day.

LOL!!!!!!!!!!!!
see Kwickies stood you in good stead, and made you what you are today
All hail to the Mort

PIZZA! PIZZA! PIZZA! PIZZA!
@slobberchops! The Hive.Pizza team manually curated this post.

PIZZA Holders sent $PIZZA tips in this post's comments:
@killerwot(3/5) tipped @oblivioncubed (x1)
harlowjourney tipped slobberchops (x1)
samsmith1971 tipped slobberchops (x1)

You can now send $PIZZA tips in Discord via tip.cc!

I am not good at coding, I thought about trying to write something like this but did not have enough knowledge. Great Job!

I really hope you will think about putting me on the list.

Python 3 made print into a proper function to be more consistent with other stuff. Look at 'f strings' for neat ways to format the output. I love Python and I get to use it for work these days. I've done various BASICs, C, C++, C#, Java and others. Python may not be the quickest, but you can produce working code more easily.

The libraries for Hive are great. People should have a play and they may create new dapps eventually.

Yes, I know about the f' thing, though its still not clear in my head yet. I aim to do some more work on the script, involving the BEEM library which can be painful (lack of examples).

Man, the people I met in person on Steem are all gone, some I miss and some I don't! It makes it better when you meet face to face in my experience.

Posted Using LeoFinance Beta

The names and the faces generally didn't match your visual expectations, that was my experience!

You can change that, just slobber all over everyone!
The rest of your post went over my head so that's why the people comment.

Posted Using LeoFinance Beta

what's the best and simple way to handle args on Python?

Practice makes a man perfect, i also learned c++ and, javascript but i didnt practice it for years.

This sounds like an interesting script. Every night I vote my account down to 90% . Sometimes I find myself voting randomly just so I can get to bed.

BTW: People can do something similar to your script simply by upvoting random posts in their feed. You can see your feed by following your account name in hive followed by /feed . Here is your feed:

https://hive.blog/@slobberchops/feed

!beer

I tend to send my VP down to around 85% before sleep, 90 is a little high considering it recharges around 20% over 24 hours. If I have to go out the next day, it may get close to 100, and that's wasteful.

Why send arguments from command line? Why not include them within the code? Are you using beem or something else?

Yes using BEEM.., or should I say struggling with it if I need to do something new!

For the most part I can simply run the script, but occasionally I wanted to up the weight, and so needed an optional argument to do this sent as an integer.

Other things I want to incorporate are checks to ActiFit posts (wont vote them), and maybe grant larger votes to content with more substance.

It's all a reason to practice coding and keep my brain fresh!

I'm going to try doing something like this as well! I've been meaning to find a Python project. Got any hints for a Python noob?

I initially got some help, especially from @steevc who gave me the vote routine. Since then I built it up, and it's getting more complex the more I add to it. Best thing is.. it taught me the language.

Got any hints for a Python noob?

I am no expert in it. @geekgirl and @felixxx are much more accomplished than I.

I'd like to toss @zedcell, @alonicus, and @killerwot into the ring as potentials for the random votes. They're all fantastic, and work their asses off!

cool, will stop by at this accounts

Thanks for the mention @oblivioncubed

!PIZZA

I know of @zedcell, the other two are added.

Much appreciated my dude!

Aw man, that's an awesome idea you're working on. I like seeing people give back into the community like that. I'd love to throw my name into the mix; I've only ever done one shit post - on purpose - and it was, in fact, of a dog taking a shit. I think I even labelled it as such.

I love python as a scripting language. It's also my "go to" when I need to do something. It's elegant. It's easy to read, and it's not javascript (oh dear god I despise javascript).

I think you are good enough to be added. One of the things I need to do is check who regularly comments and look at their writing.

image.png

@hr1 literally kept me going for several months when I started. We all need some encouragement and self-worth.

When I first started using Python I couldn't get anything out of it. Talk about frustrating, and then it clicked. It does take time to get into another language even if you are fluent in others (as am I).

I don't write much just trying to get an account built up to help nomads and travelers, hoping to bring some to Hive.
Looking to get a place to help them build out DIY and work on vehicles when they need a place to do so.

This is a great idea, as long as it is not crap posts that many users write.

Like I told Geekgirl, when I have time I really want to play around with Python. It looks like fun!

Congratulations on being in such a position to support others 🙌Is it ok to nominate a couple of people? @samsmith1971 is an amazing author, who even as a newbie supported new members. And @blindspot is a longtime member of the Hive community who is currently trying to get his life back on track after fleeing the Ukraine.

Sure, I will take a look at these accounts, I think you may already be on the list.. not sure.

EDIT: You and Sam are already on it. I have seen the account @blindspot, but the one you mention is not the correct one.. different spelling, and I can't find it.

Sorry, it's @blind-spot - @zirochka is another, she's right in the thick of the battle...

I'm honored that I am on the list :)

This is lovely, thank you @slobberchops. I have seen you on my posts before and appreciate your support. Thank you for the kind mention @wrestlingdesires. I am pleased that you are already on the list. You are immense my friend. @slobberchops, might I ask you to consider ayesha-malik, deraaa, amber-kashif, itsostylish, beautifulwreck, dreemsteem ... all beautiful ladies who write from the heart. and jin-out, litguru, tengolotodo and khoola... men with big hearts too. !LUV !ALIVE

I will take a look at these, you are in the UK? If @shanibeer ever organises a STEEM, er HIVE-Camp.. you should come.. they can be eye-openers.

I am indeed 😊, down South, near London. Camp sounds fun! I've actually just come back from California where I met up with a fellow Hiver that I only knew from the blockchain and had not met in person previously. We spent 11 days together. It was such a wonderful experience. It helped that we were both exactly the same people on chain as off so it was relaxed from the start. Finding connections like that is special. Thank you for considering my suggestions... I didn't intend to throw a ton of names at you but I couldn't choose between the few I did suggest 😁 Their hearts are all in the right place and they write with intention. I enjoy them all as writers and people when I read them and engage with them. !PIZZA

I added most of them, you have good taste! The last STEEM Camp (yeah STEEM... before the divorce) was in the middle of 2019 in Leicester.

It's generally in the Midlands so to attract the London crew and the filthy wild northerners such as me!

I added most of them, you have good taste!

That is kind of you to support them. Some of them get the occasional boost from big accounts but if that account doesn't support them then their posts earn a lot less than they are worth.

re meet ups, wow yeah 2019 before lockdowns... Midlands is good... I drive there to meet up with people occasionally😊 Not far at all.

Have a fabulous day @slobberchops❣️

It was my pleasure :)

@slobberchops! You Are Alive so I just staked 0.1 $ALIVE to your account on behalf of @samsmith1971. (2/10)

The tip has been paid for by the We Are Alive Tribe through the earnings on @alive.chat, feel free to swing by our daily chat any time you want.

This is very interesting. I can think of so many writers who consistently deliver, but are not always rewarded commensurately.

The two who immediately spring to mind are @consciouscat and @wolfofnostreet. I enjoy all of their posts, but sometimes, they are very under-rewarded. Such is life, but they certainly deserve consideration for your list.

Coincidentally, I recently also started learning Python. Early days, but still...

(I notice I have a new downvoter, positivum, who has posted nothing, but has 1000 HP and downvotes people like me but upvotes people like you and edicted. Is that insanity or do they have a goal that I don't understand because I am naïve? What is this individual's strategy? It removes about two cents from my pocket per day, which is irrelevant, but if 500 accounts did the same thing...)

!WINE
!PIZZA
!hivebits

Thanks for the mention @harlowjourney 😀 Knowing you and some others who continue engaging me keeps me going.

Thank you for your kind thoughts and inclusion here, Harlow. It's a lovely surprise. Indeed, I care about writing meaningful, useful things as often as possible. Thanks for the tag, dear one. !LUV

Meanwhile, I love that you understand enough about coding that you even clicked on this post @harlowjourney. I may be a wordsmith but I struggle to understand most of this post. I guess, as you said @slobberchops, I must be one of those types who will never understand it. Oh well, I guess it's back to the never-ending study of psychology for me 🤣 !LOL

The two who immediately spring to mind are @consciouscat and @wolfofnostreet.

Thanks, one of them had already caught my eye and is on the list.

(I notice I have a new downvoter, positivum, who has posted nothing, but has 1000 HP and downvotes people like me but upvotes people like you and edicted.

No idea who it is, the recovery account gives nothing away of it's origins. I have a stalker who has downvoted everything I post for the last 4 years. Ignore it, or mute the account if you don't want to see. It's not as if they can cause you much damage.


Congratulations, @harlowjourney You Successfully Shared 0.100 WINEX With @slobberchops.
You Earned 0.100 WINEX As Curation Reward.
You Utilized 1/1 Successful Calls.

wine_logo


Contact Us : WINEX Token Discord Channel
WINEX Current Market Price : 0.400


Swap Your Hive <=> Swap.Hive With Industry Lowest Fee (0.1%) : Click This Link
Read Latest Updates Or Contact Us