This is my first real coding tutorial contribution here. Hope it really helps people in their journey to learn about and contribute to this wonderful platform.
What Will I Learn?
- Find the total number of incoming and outgoing votes for any account
- For the same account, find the number of incoming votes from and outgoing votes to different users
Requirements
- Python 3.6
- steem-python
I use Windows and it is difficult to easily install steem-python on a Windows machine. This tutorial written by me should help out on that.
Difficulty
- Basic
Tutorial Contents
Step 0 - Basic Setup
In order to get this program running you first need to perform some basic steem-python
set up activities in your machine including setting up nodes which are essential for accessing the blockchain.
All necessary details can be found in the below tutorial:
Part 0: How to install steem-python in Windows
Step 1 - Import Libraries
The first step for any python program is of course to import the necessary libraries. You will see how these libraries are used in the following steps.
Image Credit: @svkrulze for this and all following images
Step 2 - Function definition
This is the function which does all the work in the program. It accepts the Steemit accountname for which the analysis is to be done and the start and end dates for the period for which the report needs to be created.
The function returns a dict
of users and incoming and outgoing votes to and from those users vis-a-vis the Steemit account for which the report is being generated.
Step 3 - Date formatting
The dates received as YYYY-MM-DD need to be formatted. Please note how the end date is modified to include the entire day's time. If those 23 hours, 59 minutes, 59 seconds are not added then the program will not be able to fetch data for the end date as it will consider only till 12 AM of the end date which is really the beginning of the day.
Step 4 - Initial message and variable declaration
Two dictionaries are declared here along with two integer variables, these will be used shortly.
posts
is a dictionary to store number of votes and voters list
authors
is a dictionary to store usernames and count of incoming and outgoing votes
Step 5 - Main loop
Account.history_reverse()
is used with filter_by="vote"
to fetch only votes and not all the other data which is unnecessary for our purpose. The history_reverse()
function is used instead of the history()
function to make sure the latest vote by a user (after vote changes, vote deletions etc.) is picked up.
The for loop goes through all the votes received and given by the account in reverse order.
Votes within the provided timeframe are only considered [if time_voted >= start and time_voted <= end
].
A new post is added to posts
by using permlink
each time a new one is encountered.
Also note how votes with non-zero weights [if vote['weight'] == 0
] are considered only by setting the vote value to 0 when there is a zero-weight vote. Negative votes are counted and not ignored or subtracted from the total vote count.
When a post is already present in posts
and a voter who is already in the list of voters for that post is encountered again i.e. an earlier vote which was later revised, such an old vote is not considered [if vote['voter'] not in posts[permlink]['voters']
].
When vote is on an already encountered post but from a voter who has not been encountered for that post, the vote count for the post is increased and the voter list updated.
Step 6 - Votes to and from different users - still within Step 5 for
loop
When a vote is valid as per Step 5, a check is performed whether the voter is the account in consideration for the report or not and accordingly the authors
dictionary is updated with the vote either as incoming or outgoing.
Step 7 - Break out of Step 5 for
loop
Break out of the loop when voting time is before the start time for the report.
Step 7 - Print results and return user list
Finally, once the for
loop goes through all votes for the account within that timeframe, the results are printed using the authors
dictionary and the same is returned by the function.
Step 8 - One call to run it all
The easiest thing to do remains: call the function passing the accountname
and start and end dates.
Results
The results are displayed when the program is run. The below printscreen is a partial one showing the first few lines of the output.
Please note
Consider the date range you provide, as a long date range or a date range from quite some time back will take longer to run as the code has to traverse the blockchain sequentially from the newest to the oldest.
Hope this helped you in some way! Would love to know how it helped you in the comments section below.
Curriculum
Part 0: How to install steem-python in Windows
Source Code
Full source code for this tutorial can be found on Github.
Goodies: Benefits for You (Referral Links)
Sell Votes on SmartSteem
Get Followers and Upvotes on SteemFollower
Get Free Crypto Coins
Click on the banners to learn more about each community
Your contribution cannot be approved because it does not follow the Utopian Rules.
Violated Rule(s):
My Opinion(s):
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @yokunjon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post bro. Thanks for sharing✌
Have a great time ahead @svkrulze.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You have been scouted by @promo-mentors. We are always on the look out for promising authors.
I would like to invite you to our discord group https://discord.gg/vDPAFqb.
When you are there send me a message if you get lost! (My Discord name is the same as the one here)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 5 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.
I upvoted your contribution because to my mind your post is at least 22 SBD worth and should receive 70 votes. It's now up to the lovely Steemit community to make this come true.
I am
TrufflePig
, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!Have a nice day and sincerely yours,
TrufflePig
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Frends! Can you help me one matter?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Please tell me.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I would like to create content with ico in utopian.io. But I will choose one of these here? do not understand.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I don't understand what you mean by creating content with ico... can you explain please?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
If I upload my content about ico or cryptocurrency at utopian.io, then choose which one from here?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Utopian is for open source contributions... There is no separate option for ICOs. If you are developing an open source ICO project, you can submit it in Development category I think but make sure you read the rules first. Here is an invite to the utopian-io discord. Check there if you need more information. https://discord.gg/bYA2J5
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit