Created
February 4, 2020 23:28
-
-
Save emre/0b3dcb67545a0a53b6aeecf5cf2a3148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lightsteem.client import Client | |
c = Client(nodes=["https://api.steemit.com"]) | |
PROPOSAL_ID_REQUESTING_FOUR_WEEKS_PD = 53 | |
PROPOSAL_ID_REQUESTING_THIRTEEN_WEEKS_PD = 71 | |
WITNESS_ACC_TO_MAIN_ACC_MAP = { | |
"smooth.witness": "smooth" | |
} | |
def map_witness_to_main(username): | |
return WITNESS_ACC_TO_MAIN_ACC_MAP.get(username, username) | |
def get_witnesses(): | |
""" | |
Returns the ranking of a specific witness | |
If only the witness is inside top100. | |
""" | |
top_100 = c('condenser_api').get_witnesses_by_vote("", 100) | |
return [map_witness_to_main(w["owner"]) for w in top_100] | |
def get_proposal_voters(proposal_id): | |
proposal_votes = c('database_api').list_proposal_votes({ | |
"start": [proposal_id, ""], | |
"limit": 1000, | |
"order": "by_proposal_voter", | |
"order_direction": "ascending", | |
"status": "all" | |
}) | |
filtered_voters = [] | |
for proposal_vote in proposal_votes['proposal_votes']: | |
if proposal_vote["proposal"]["id"] != proposal_id: | |
break | |
filtered_voters.append(proposal_vote['voter']) | |
return filtered_voters | |
witness_list = get_witnesses() | |
voters_four_weeks = get_proposal_voters(PROPOSAL_ID_REQUESTING_FOUR_WEEKS_PD) | |
voters_thirteen_weeks = get_proposal_voters( | |
PROPOSAL_ID_REQUESTING_THIRTEEN_WEEKS_PD) | |
# witnesses | |
witness_list = get_witnesses() | |
witnesses_voted_for_four_weeks = list( | |
set(witness_list).intersection(voters_four_weeks)) | |
witnesses_voted_for_thirteen_weeks = list( | |
set(witness_list).intersection(voters_thirteen_weeks) | |
) | |
print(witnesses_voted_for_four_weeks) | |
print(witnesses_voted_for_thirteen_weeks) | |
# table = """ | |
# | Witness | Support to 4 weeks PD | Support to 13 weeks pd | No vote | | |
# |--------|----------|--------------|-----------------------|---------|""" | |
# | |
# for supporter_witness in witnesses_voted_for_four_weeks: | |
# table += "\n|%s|%s|%s|%s|" % (supporter_witness, 'Yes', 'No', '-') | |
# | |
# for conservative_witness in witnesses_voted_for_thirteen_weeks: | |
# table += "\n|%s|%s|%s|%s|" % (conservative_witness, 'No', 'Yes', '-') | |
# | |
table = """ | |
| Witness | | |
|---------|""" | |
for supporter_witness in witnesses_voted_for_four_weeks: | |
table += "\n|%s|" % (supporter_witness) | |
print(table) | |
table = """ | |
| Witness | | |
|---------|""" | |
for conservative_witness in witnesses_voted_for_thirteen_weeks: | |
table += "\n|%s|" % (conservative_witness) | |
print(table) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment