Python Libraries: Self-Vote Checking, The FAST Version!

in STEMGeeks2 days ago

Cover.JPG

RedLine.png

...'THE SLOBBERCHOPS WHITELIST'...

Would you like to be whitelisted and eligible for votes by me (and a bunch of other accounts?). Drop me a comment on this post, and I may add you (subject to account checks).

Twice or three times a day I manually run the BOT until the voting thresholds on all the accounts have been breached. You may get a vote, or you may be passed by.

A vote depends on passing the checks I have put in place, and if your name is randomly picked. There's nothing to lose, you get votes, could be small or large and I get curation rewards.

RedLine.png

DISCLAIMER: Self-voting is a personal preference. It is completely up to you what you vote for and who. Never let anyone tell you what to do with your stake, it's yours and yours alone.

After looking at some code from @gwajnberg, I figured this was it! A self-voting checking code routine, something I had been putting off for a while due to combination of sullied procrastination laced with pure apathy.

After some farting about, I managed to get @gwajnberg's routine working and work it did albeit very slowly. My last patch had increased the speed of the HIVE Voting BOT, by ensuring accounts were only processed once, so I was loathe to add anything to slow it down.


image.png
...'Chat-GPT is far too polite, I would have told myself to fuck off'...

It was time to make something quick and efficient and that meant HIVE-SQL. Although things are starting to click, SQL is hardly my forte, so I asked Chat-GPT for some help.

A fat lot of fucking good that did, and after a while I was calling that AI a useless bastard, a statement it tends to shrug off with ease. Wrong result, even though I explained it properly.

Garbage-in, Garbage out @steddyman tells me. It's true sometimes.

Taking things back to basic, I gradually built up the code and requested a single output, otherwise when I call it from Python I get all this other bullshit that's not needed.

SELECT 
ROUND(
    FLOOR((CAST(SUM(CASE WHEN voter = author THEN weight ELSE 0 END) AS FLOAT) 
    / CAST(SUM(weight) AS FLOAT)) * 1000 * 100) / 1000, 2
) AS self_vote_percentage
FROM txvotes
WHERE 
    voter = 'greedy' 
    AND weight > 0 
    AND timestamp > GETDATE() - 7;

This returns what I want and nothing else. I am not interested in the parameters used for the calculations, just the result code.

image.png

Now it was a question of getting it into Python. For this, you will need a valid HIVE-SQL account, and this can be obtained here.

It will cost you 1 HBD for an account and don't lose your credentials or it will cost you another to get them reset. I speak from personal experience.

To date, I had only a single SQL-HIVE routine in the HIVE Voting BOT, and now there were two calls. The SQL routine had to be callable using parameters so I had to make several adjustments.

I hate duplicating code, it's shitty practice and something I have fallen foul of in past scripts, so I make a point of avoiding it now.

def get_hiveSQL_data(SQLCommand, conn): 
# Accepts SQL queries and returns values

cursor = conn.cursor()
cursor.execute(SQLCommand)
result = cursor.fetchone()
cursor.close
conn.close

if len(result) == 1:
    return (result[0]) if result else (None)
elif len(result) == 2:        
    return (result[0], result[1]) if result else (None, None)

What boring-looking code, and where's the fucking swearing?

It is boring but is now callable, and depending on the parameters will return up to two values. Unlike many other languages Python allows separate values to be passed back to the function call, it's one aspect I really like about it.

    # Test # 1 - Are you a Self-Voting Motherfucker? - How greedy can you be?
    # Gets the Self-Voting Percentage
    SQLCommand = f'''
    SELECT 
    ROUND(
            FLOOR((CAST(SUM(CASE WHEN voter = author THEN weight ELSE 0 END) AS FLOAT) 
            / CAST(SUM(weight) AS FLOAT)) * 1000 * 100) / 1000, 2
    ) AS self_vote_percentage
    FROM txvotes
    WHERE 
        voter = '{account}' 
        AND weight > 0 
        AND timestamp > GETDATE() - 7;
        '''            

    self_vote_percentage = get_hiveSQL_data(SQLCommand, connection_string)

When the call is like this, it makes a little more sense, much more...

connection_string = pypyodbc.connect(
    f'Driver={{ODBC Driver 18 for SQL Server}};'
    f'Server=vip.hivesql.io;'
    f'Database=DBHive;'
    f'TrustServerCertificate=yes;'
    f'uid=Hive-{mainaccount};'
    f'pwd={sql_password}'
)

conection_string only needs to be defined once, and so is close to the top of the script within the declarations area.

import pypyodbc

def get_self_vote_percentage(account): 

conn = pypyodbc.connect(
    'Driver={ODBC Driver 18 for SQL Server};'
    'Server=vip.hivesql.io;'
    'Database=DBHive;'
    'TrustServerCertificate=yes;'
    'uid=Hive-username;'
    'pwd=password'
)

cursor = conn.cursor()

SQLCommand = f'''
SELECT 
ROUND(
    FLOOR((CAST(SUM(CASE WHEN voter = author THEN weight ELSE 0 END) AS FLOAT) 
    / CAST(SUM(weight) AS FLOAT)) * 1000 * 100) / 1000, 2
) AS self_vote_percentage
FROM txvotes
WHERE 
    voter = '{account}' 
    AND weight > 0 
    AND timestamp > GETDATE() - 7;
'''

cursor = conn.cursor()
cursor.execute(SQLCommand)
result = cursor.fetchone()
cursor.close
conn.close

return result[0]

account = "greedy"
self_vote_percentage = get_self_vote_percentage(account)
print(f' Account {account} has a self-vote percentage of {self_vote_percentage}%')

To make it easier for you to use this yourself (above), I isolated the whole routine so it can be modified to your needs.

Replace 'greedy' with an account of your choice, and change the name and password to your credentials.

HowGreedyCanUBe0.JPG

Adding the routine to the HIVE Voting BOT was not a big deal. I have completely rewritten it and made it a lot more modular than the abomination that @felixxx once cast his eyes on about a year ago.

It was time for some fun, and I was pleasantly surprised at the amount of accounts that didn't self-vote at all.

cutoffs.JPG

First, declare some cut-off values, there's little left to the imagination here.

.. and then running it in anger which is always fun. It picked up just two authors who like to vote themselves a little more than they should and the BOT does not hold back.

greedy.JPG

Nothing personal to this user..., quit the self-voting and it will forget about you in a week, and you might just get votes again. It has a short-lived memory and is completely non judgemental... honest!

Another routine added; I think I might just give all the 0% self-voters authors a bonus of 1.

Lastly... this function is no slouch, it's rapid!

RedLine.png

Do you like posting your Urbex content and photography for FREE on Facebook and YouTube? I like to get some form of reward for my work and every time I create I do just that. Take a look at The Urbex Community on HIVE.

If you want to keep creating for FREE then ignore what you are reading. If you want to be like me and gain something other than BUGGER ALL for your work then click here and learn about posting on the HIVE blockchain.


My Urban Exploration Tales can be found directly on the internet via my
Website: 'Tales of the Urban Explorer'.

RedLine.png

TalesLogo.JPG

RedLine.png


CurieCurator.jpg

RedLine.png

Drooling Maniac.JPG

If you found this article so invigorating that you are now a positively googly-eyed, drooling lunatic with dripping saliva or even if you liked it just a bit, then please upvote, comment, rehive, engage me or all of these things.

Sort:  

I'm so glad there are so many kind hearted and clever nerds techies around who can help on Hive

It's more a question of.., 'who do I vote for'.., a sad case of affairs. Can we get just two or three from the mountains of new accounts who ditch HIVE after a few months who might become Orca's.

'What mountains?'.. you say..

Maybe hillocks in todays world..

Ah the self voting arses!

I like to think I all a dab hand at SQL but that query you have is something else!

It was a lot larger until I cut out all the blurb I didn't need. For a call via Python, you just need the pertinent data and not all that other stuff like what's the data called etc.., that's for queries running through the likes of Linqpad, which is what I use to develop them.

Would you like to be whitelisted and eligible for votes by me?

YES

I don't see an issue with your account, .. added.

image.png

Thanks very much

Nice job. I didnt know about Hive SQL’s existence. But seems like it could make a lot of things faster than what API is offering including the limits on fetching data….
Can you add my username into your bot? @vixmemon

I surely can add you, for an old account you don't get much exposure? Your shorts will not get voted, but the longer content may get the BOT's attention.

Yes - I would like you to add me to your list

98a3c9a5de0669d196b11a3d88c83815_h-246.gif

I would be happy to, but as your account stands now, it won't vote you due to your delegation preferences. Added in case anything changes.

image.png

I understand you - but is it bad to delegate to various interesting communities? (probably I don't understand something) - in any case, thanks for answering

It's not bad, its a preference. My ideals are different to yours.

Fair enough. The world would be boring if everyone had the same ideals.
!BEER

Still this codes still seems like a complex universe.However, this post shows certain shortcuts to learn about it and I thank you very much

To me, all this looks about as tidy and presentable as a trip through nasty brambles and over barricades in to a perilous window left open, graffiti and fresh fire evidence with a chance of meeting a vagrant living there.

I should stand on the sidewalk muttering something about calling the police on you lot. Fuckin urban explorers.

You just need your brain re-wiring.., that's all. Mine's wired for code and tripping over brambles.., which reminds me, I need to schedule a Sheffield UX trip soon with the boys.

It's been a good while since I've fiddled with anything SQL, even then it was only rather simple stuff like managed account data and post data for websites.

That being said I will be diving into it again soon™ when it becomes needed for some of my projects that are in the works and should be done soon™

There's a lot you can do with HIVE-SQL, it's adding the correct parameters to get what you need. I will be brushing up on it, but will avoid using it in the BOT when I can call the condenser (or BEEM at a push) API's.., unless they slow things down.

This blog has a lot of coding stuff that is hard to understand for me.

I would like to be added to THE SLOBBERCHOPS WHITELIST however I am not sure if I am eligible being a newbie. My vote has no value atm but in future, it will have. I read in a few blogs that most people don't like self-voting and my mentor also told me about it. I would never do this as well and I find hive such a great place in crypto and web3 world.

I actually added you around a week ago, but as your account is < 90 days old, the BOT will by-pass your posts. But you are in there for the future.

image.png

My vote has no value atm but in future, it will have.

Once upon a time, my didn't either. Build it up over time, and buy some HIVE if you want to speed things.. like I did in March 2018 on joining.

I actually added you around a week ago

Oh wow, thanks a ton for this and I didn't even know this. I have got so many gifts and good surprises on hive so just love this place.

I am planning to buy Hive and SPS coins soon. You will see me talking about my purchase soon. In fact, my research says that hive is down by 90% approx so a good time to bag some coins. I am going to start by buying soon and this is my long-term planning here.

So much new stuff is here for me and I am learning as much as I can. Thanks again for this kind gesture and I wish you a fabulous weekend.

Thanks again for this kind gesture and I wish you a fabulous weekend.

You are very welcome.., I see it as the only way to get people interested is to support the smaller accounts.., not ignore them. Where else can you jump on somewhere and get free votes

100% agree.
I can say this support means a lot to me and tbh I dont know where can I get free votes.
Your initiative to support smaller accounts is such a great one on this network. Kudos to you ser

Nice work. I like those insights into other coders' minds. Helps me a lot.

Is your bot code public somewhere?

Is your bot code public somewhere?

It's not, maybe one day I will release it on github.

THE SLOBBERCHOPS WHITELIST

Would make a good name for a prog rock band 🤭

I am partial to prog, could be a memorable band name?

Even better, THE SLOBBERCHOPS WHITELIST PROJECT

Now that's reminding me of Alan Parsons 😀

It's been so long since I really touched code deep :( lol AI is making it easier.

lol AI is making it easier.

Lots of professional coders use it now, speeds things up no end. If only I could find a curmudgeon flavoured one, that would make my day 😃..

Hive-SQL is nice ... I hope that it continues to be available for all the users like it is right now for 1 HBD (very cheap).
One criticism that I have is that it is built on MS SQL server, why not doing it in PostgreSQL? Installing the ODBC Driver is so annoying (or I am too grumpy). I have used my whole life PostgreSQL and there are some syntax differences that I only usually notice when the query continues to get a bad answer from the server hehe.

It's not especially my strong point, hence the semi-fruitless chat I had with AI. I don't see it as a big job to convert, it's something you can probably use, and requires minimal changes.

@mahdiyari runs a free node, so you could check that, I don't know what flavour of SQL he's running.

for sure AI can help...sometimes I chat to ask about ideas to solve some problems, what I used to do before, just "asking" to google.

Yeah I will check that for sure! thanks!

I would not be without it, but when it comes to HIVE Python code, it does give back a lot of guesses. I get results from it, but you still need to know your shit, if you want a decent result. It's a great google substitute, as you say.

Hahhaa i feel that in other things that I do like R … too limited sometimes

SQL is pretty cool once you get the hang of it. I kind of wish I had spent more time on it back in University. I think I could have made a pretty good career of it. I need to set up some voting routines myself to try and spread my vote around a bit more.

I find it very abstract, but am slowly getting there. There could be a lot more I could do if I could conjure up scripts quickly... esp. concerning abuse. It's one aspect I will be focusing one more soon.

Looking forward to seeing what you come up with!

So does self voting disqualify me from this? I was told years ago that it didn't matter so I vote on my content as soon as I post it

In your case yes, but it only looks at the last 7 days, not forever so that could change.

image.png

Your KE ratio would also disallow votes.

image.png

That's good to know, I'll stop self voting and follow

Curious about HivePakistan? Join us on Discord!

Delegate your HP to the Hivepakistan account and earn 90% of curation rewards in liquid hive!

50 HP
100 HP
200 HP
500 HP (Supporter Badge)
1000 HP

Follow our Curation Trail and don't miss voting!

Additional Perks: Delegate To @ pakx For Earning $PAKX Investment Token


Curated by gwajnberg


The rewards earned on this comment will go directly to the people( @vixmemon ) sharing the post on Reddit as long as they are registered with @poshtoken. Sign up at https://hiveposh.com. Otherwise, rewards go to the author of the blog post.

Interesting topic! Python libraries are powerful tools, and autovote verification can be helpful in maintaining transparency in online communities. If you're looking to streamline the process, Python is definitely a great option. Good choice!

If you're looking to streamline the process, Python is definitely a great option. Good choice!

Yes, I thought so too.

Glad I learned that self voting is not OK :)

It's a debatable topic, and much like everything else on a platform based around anarchy, everyone has their opinions. People will notice that you vote for yourself and that vote intended for you, may go elsewhere if they think like me.. or not!

That's awesome

Add me please!

You are going to have to up the quality of your posts before I do that. Do they add anything, make people laugh, increase our knowledge, or are they just about you and your increasing assets?

I see many posts like yours, and they add no value whatsoever.

I think they are useful for Splinterlands players. But other people can have a different opinion, that's ok. Thanks anyway.

Cool initiative! I started learning coding around a year ago for work and it's made my professional life so much easier. This reminds me I should be implementing a few things to my personal and digital life as well.

I'm no fan of self-voting, so I can put me off supporting people, especially if they have a big stake.

Python f-strings are great and so much better than the old methods they had to get variables into a string. I did loads of SQL at my last job, so I love HiveSQL. It's easy to test queries. I use a thing called dbeaver on Linux for that. Then I can add them into my code.

PIZZA!

$PIZZA slices delivered:
@danzocal(3/10) tipped @slobberchops

Interesting code.
I love to play around with this automation available in python Hive library.
Can you share a report on the lucky hivian who got upvotes from the bot?
Also figures on the percentage that was not consider or remove over the period of the bot service.
Thank you

Would you like to be whitelisted and eligible for votes by me?

I want to join this list

DISCLAIMER: Self-voting is a personal preference.

I always vote for my posts myself. It was default back in the days that you vote for your own posts, until it was considered sub-optimal because of the reverse-auction anti-bot protection during first minutes of posts' life.
Actually enforcing self votes at the blockchain level could bring interesting counter-intuitive results; those who will spam with posts looking for rewards, will strip themselves from potential curation rewards, as most likely not only their self votes will be countered, but also there will be no voting power left for other "safe bet" curation reward targets.