Python Libraries: Expanding the Functions
Apologies but this will be too heavy for most readers. For Python coders, it may be semi-legible.I recently wrote a couple of functions to further support the RandomVoter script. One reason is to stop my head from falling into decay as I now haven't worked for around 9 months.
They say IT still has great demand, but not for my niche. At my age I don’t know whether I can be arsed to re-skill and if Splinterlands Land takes off next year, then maybe I will never need to.Learning Python has been quite fun, and it’s an easy language once you get your head around it. I struggle more with the BEEM library due to inadequate documentation.Technical people are not re-known for making great docs, and I am a testament to that.I am unsure whether to make a GitHub repository for all these bits of code. I don’t mind sharing but my confidence as a programmer has never been great.In the commercial world, I have written many scripts that have been used but have always seen myself as a hack n' slash coder, and that more orthodox coders would sneer at my badly written efforts.The main thing is that I can get things to work, and that is more important to me than structure and order. I have never been a great fan of Actifit posts. I see some that a quite meaty in content and I do upvote these posts if I follow the authors and they are to a good standard.What I don't want happening is for the RandomVoter script to upvote them as quite often I won't look or inspect their innards.I needed a way to detect the tags used from the post object and then skip the vote if #actifit was present.There used to be a method ‘get_tags_used_by_author’ which no longer works. @foxon mentioned in a discord session this had been discounted in HF24.
Thanks to @steevc who has used an alternative method I dissected his GitHub code and figured out an easier way.“tags” is an attribute of the comment property but tough to find in Holger's documentation, or at least with examples.strnovotetag holds the tag for pending posts that I don't want to curate.Like many of my functions, it returns a Boolean value for the result code.Next, I needed to add the Def into my main script with some If commands to skip voting depending on the results. My list of votees does contain some accounts that I follow. While I am happy that the four smaller accounts curate these authors, I did not want my large @slobberchops one included.I generally curate my followers manually and wield larger votes than the default weight of 5% used with RandomVoter.It would be great if I could detect the accounts on the list, check if @slobberchops is following them, and skip that vote.This way all accounts benefit from the smaller votes and I can manually hand out bigger ones to accounts I follow.
This one was quite easy to lift from Holger's documentation and took less than 30 minutes to craft in my usual style.I used @meesterboom as the followed account is the string strvotee and my account in strmainvotingaccount.Like detecttag this function returns a Boolean value and can easily be adapted into the main script, or so I thought!After some tinkering to the main script, the release notes added and an updated version (2.0) yielded the result I was looking for worked.Incorporating the functions into the main script took longer than writing both routines. Perhaps it is my bad structure, which I am fully aware of.
The voting code needed to be relocated into a separate function as I am not a fan of duplicating code. It looks a little more structured now and contains the call to the check posts that have already been voted.The issue I had was to ensure both functions would be enumerated correctly and I needed to resort to using a Boolean variable named slobbervote which would be set to False if the isfollowed function returned False.
Maybe there is a more elegant solution to my solution but as I have said before, I am still learning and am no coding genius.To test I needed accounts that have posted in the last 24 hours, one that I follow and one that is an Actifit post.
For this I can comment out the getrandaccount function that returns.., what do you know!.. a random account to vote on, and hard code in other accounts.
Thanks, @chekohler for being my guinea pig on this one. I can see it works and @chekohler will now get random votes from my smaller accounts but not the @slobberchops account as I tend to manually curate his work.
@trezzahn is another author who I follow and exclusively uses the Actifit tag. This account was perfect for testing my other function, or was it?
Like the previous example, the code exited when it discovered I follow @trezzahn. There is no requirement to check for the Actifit tag as I follow this author.
For the final test, I needed an author who was on my vote list, who I didn't follow, and who used ActiFit tags in their post.
I couldn't find one immediately so scanned ALL ActiFit posts. This is why I don't want to auto-curate these posts. Most of them are sparse..I could say shit, but each to their own!