Skip to content

Instantly share code, notes, and snippets.

@AceSevenFive
Created May 15, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AceSevenFive/047517e18e5da14c922eb240c428d8f8 to your computer and use it in GitHub Desktop.
Save AceSevenFive/047517e18e5da14c922eb240c428d8f8 to your computer and use it in GitHub Desktop.
def countVotes(link):
submission = reddit.submission(url=link)
votedict = {"Bills": [x.replace("Y", "").replace(": ", "") for x in re.findall("([CSM]\-\d\d:\sY)", submission.selftext)]}
for x in [x.replace("Y", "").replace(": ", "") for x in re.findall("([CSM]\-\d\d:\sY)", submission.selftext)]:
votedict[x] = {"Yea": 0, "Nay": 0, "Abstain": 0}
for x in re.findall("((C|S|M)-(\d+):\s)([Yy]ea|[Nn]ay|[Aa]bstain|[Oo]ui|[Nn]on|[Aa]bstention)", "".join([y for y in [x.body.replace("\n", "") for x in submission.comments] if not re.match("^P", y)])):
if(x[0].replace(": ", "") in votedict["Bills"]):
if(x[3] in ["Yea", "yea", "Oui", "oui"]):
votedict[x[0].replace(": ", "")]["Yea"] += 1
elif(x[3] in ["Nay", "nay", "Non", "non"]):
votedict[x[0].replace(": ", "")]["Nay"] += 1
elif(x[3] in ["Abstain", "abstain", "Abstention", "abstention"]):
votedict[x[0].replace(": ", "")]["Abstain"] += 1
for x in votedict["Bills"]:
print(x + ": " + str(votedict[x]["Yea"]) + " Yea, " + str(votedict[x]["Nay"]) + " Nay, " + str(votedict[x]["Abstain"]) + " Abstentions")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment