Created
January 13, 2019 17:37
-
-
Save emre/1547b6908d9af789d34c9e4be31c052d to your computer and use it in GitHub Desktop.
sm_giveaway.py
This file contains hidden or 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
import requests | |
from lightsteem.client import Client | |
import random | |
def get_proxy_votes(c, username): | |
account_detail = c.get_accounts([username])[0] | |
if account_detail["proxy"]: | |
# print(f"proxy found, checking {account_detail['proxy']}") | |
return get_proxy_votes(c, account_detail["proxy"]) | |
else: | |
return account_detail["witness_votes"] | |
def main(): | |
c = Client() | |
poll_data = requests.get( | |
"https://dpoll.xyz/api/v1/questions/emrebeyler/?permlink=steemmons" | |
"ters-choose-a-dragon-and-win-a-legendary-card").json() | |
choice_count_map = {} | |
for choice in poll_data["choices"]: | |
choice_count_map.update({ | |
choice["text"]: { | |
"vote_count": len(choice["voted_users"]), | |
"voters": choice["voted_users"]} | |
}) | |
winner_choice = max( | |
choice_count_map.items(), key=lambda x: x[1]["vote_count"]) | |
print("Winner choice:", winner_choice[0]) | |
eligible_voters = [v["username"]for v in winner_choice[1]["voters"]] | |
account_details = c.get_accounts(eligible_voters) | |
voters_with_bonus = [] | |
for account_detail in account_details: | |
voters_with_bonus.append(account_detail["name"]) | |
if account_detail["proxy"]: | |
proxy_votes = get_proxy_votes(c, account_detail["proxy"]) | |
if "emrebeyler" in proxy_votes: | |
voters_with_bonus.append(account_detail["name"]) | |
elif "emrebeyler" in account_detail["witness_votes"]: | |
voters_with_bonus.append(account_detail["name"]) | |
random.shuffle(voters_with_bonus) | |
print("Tickets", voters_with_bonus) | |
print("-" * 42) | |
print("And the dragon goes to... 🏆 ", random.choice(voters_with_bonus)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment