Skip to content

Instantly share code, notes, and snippets.

@Quasimondo
Created January 30, 2022 08:41
Show Gist options
  • Save Quasimondo/d0088a1473f5a8f1f8040444011610ce to your computer and use it in GitHub Desktop.
Save Quasimondo/d0088a1473f5a8f1f8040444011610ce to your computer and use it in GitHub Desktop.
import json
from urllib.request import urlopen
def get_query_result(query, timeout=10):
with urlopen(query, timeout=timeout) as request:
if request.status == 200:
return json.loads(request.read().decode())
# Get the list of users allowed to vote
hen_users = get_query_result("https://vote.hencommunity.quest/hen-users-snapshot-16-01-2022.json")
#I used https://api.tzkt.io/#operation/Accounts_GetOperations to download all henvote operation into two json files:
votes = json.load(open("henvotes.json","r")) + json.load(open("henvotes2.json","r"))
poll_id = "QmVSWZZcBT6zRrcZM6hf9VZJ7Qha5GXUBScQowJJ7fYQxT"
eps = {}
p={}
snd = {}
for i in range(len(votes)):
vid = votes[i]["parameter"]["value"]["poll_id"]
ep = votes[i]["parameter"]["entrypoint"]
if vid != poll_id or ep!="vote":
continue
ep = votes[i]["parameter"]["value"]["vote"]
sd = votes[i]["sender"]["address"]
if not sd in hen_users:
print("disqualified",sd)
continue
id = votes[i]["id"]
if sd in snd:
if snd[votes[i]["sender"]["address"]][1]<id:
print("changed vote",snd[votes[i]["sender"]["address"]][1],id)
eps[snd[votes[i]["sender"]["address"]][0]]-=1
else:
continue
if not ep in eps:
eps[ep]=0
eps[ep]+=1
snd[votes[i]["sender"]["address"]] = [ep,id]
print(eps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment