# -*- coding: utf-8 -*- import urllib2 import json import operator import os from collections import defaultdict os.system('cls') games = 5000 range = [860000, 970000] count = 0 common_words = defaultdict(int) common_champions = defaultdict(int) exclude = ['a', 'i', 'me', 'why', 'to', 'and', 'my', 'you', 'dont', 'with', 'what', 'in', 'are', 'more', 'so', 'have', 'not', 'for', 'no', 'is', 'yes', 'im', 'u', '?', 'the', 'or', 'do', 'this', 'your', 'on', 'we', 'they', 'our', 'it', 'just', 'go', 'he', 'all', 'that', 'ur', 'who', 'of', 'can', 'its', 'get', 'cant', 'it\'s', 'can\'t', 'don\'t', 'i\'m', 'now', 'if', 'got', 'ss'] for i in xrange(range[0], range[1]): if count == games: break os.system('cls') print '%s/%s games analyzed' % (count, games) try: request = urllib2.urlopen('http://euw.leagueoflegends.com/tribunal/en/get_reform_game/' + str(i) + '/1/') except: continue data = request.read() if (data == ''): continue data = json.loads(data) for message in data['chat_log']: if message['association_to_offender'] == 'offender': words = message['message'].split() for word in words: word = word.lower() if not word.isdigit() and word not in exclude: common_words[word] += 1 for player in data['players']: if player['association_to_offender'] == 'offender': common_champions[player['champion_name']] += 1 break count += 1 common_words = sorted(common_words.iteritems(), key=operator.itemgetter(1), reverse=True) common_champions = sorted(common_champions.iteritems(), key=operator.itemgetter(1), reverse=True) print 'Words used: ', len(common_words) for i in xrange(30): print common_words[i][0], ' - ', common_words[i][1] print print for i in xrange(30): print common_champions[i][0], ' - ', common_champions[i][1]