Skip to content

Instantly share code, notes, and snippets.

@hanss314
Created November 20, 2017 03:32
Show Gist options
  • Save hanss314/d2afb9ec5c3b0bea6505c75f32dc7b7c to your computer and use it in GitHub Desktop.
Save hanss314/d2afb9ec5c3b0bea6505c75f32dc7b7c to your computer and use it in GitHub Desktop.
bfb vote counter
'''
Copyright 2017 hanss314
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
'''
Paste the results from https://github.com/fernozzle/yt-comments
into a file called "comments.json" and run the script
'''
import json
import re
vote = re.compile('\[[a-hA-H]\]')
votes = {}
results = {}
with open('comments.json', 'r') as comment_file:
comments = json.load(comment_file)
for comment in comments.values():
if 'content' in comment and 'userId' in comment:
content = comment['content']
match = vote.match(content)
if match:
votes[comment['userId']] = match[0].upper()
for vote in votes.values():
try:
results[vote] += 1
except KeyError:
results[vote] = 1
print(f'Total votes: {sum(results.values())}')
for k, v in sorted(list(results.items())):
print(f'{k}: {v}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment