Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Twitch chat listener voting script:
- inputs = [
- {"username": "ShadowsDieAway", "input": "12 16"},
- {"username": "TheNewGeezer", "input": "5 24"},
- {"username": "YoYoYoDude1", "input": "24 16"},
- {"username": "ShadowsDieAway", "input": "11 11"},
- {"username": "TheNewGeezer", "input": "24 5"},
- {"username": "YoYoYoDude1", "input": "lol 16"},
- {"username": "ShadowsDieAway", "input": "5 5"},
- {"username": "TheNewGeezer", "input": "9 9"},
- {"username": "YoYoYoDude1", "input": "2 2"},
- {"username": "failure", "input": "lol hahaha"},
- {"username": "failure", "input": "3"},
- {"username": "failure", "input": "5 7 8"},
- {"username": "failure", "input": "nope"}
- ]
- votes = []
- votes_x = {}
- votes_y = {}
- def range_x(x): return 1 <= x <= 25
- def range_y(y): return 1 <= y <= 19
- def top_votes(type):
- sort = sorted(type.items(), key=lambda (k,v): v, reverse=True)
- return map(lambda x: "{0}: {1}".format(x[0], x[1]), sort)
- for input in inputs:
- # parse
- username = input['username']
- vote = input['input'].split(" ")
- for i, v in enumerate(vote):
- try: vote[i] = int(v)
- except ValueError: vote[i] = 0
- # cull
- usernames = map(lambda x: x[0], votes)
- # validation
- if username not in usernames and len(vote) == 2 and range_x(vote[0]) and range_y(vote[1]):
- votes.append([username, vote[0], vote[1]])
- if vote[0] in votes_x: votes_x[vote[0]] += 1
- else: votes_x[vote[0]] = 1
- if vote[1] in votes_y: votes_y[vote[1]] += 1
- else: votes_y[vote[1]] = 1
- print votes
- print top_votes(votes_x)
- print top_votes(votes_y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement