This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 17th, 2014  |  syntax: Python  |  size: 1.85 KB  |  views: 4,122  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # -*- coding: utf-8 -*-
  2.  
  3. import urllib2
  4. import json
  5. import operator
  6. import os
  7. from collections import defaultdict
  8.  
  9. os.system('cls')
  10.  
  11. games = 5000
  12. range = [860000, 970000]
  13.  
  14. count = 0
  15.  
  16. common_words = defaultdict(int)
  17. common_champions = defaultdict(int)
  18.  
  19. exclude = ['a', 'i', 'me', 'why', 'to', 'and', 'my', 'you', 'dont', 'with', 'what', 'in',
  20. 'are', 'more', 'so', 'have', 'not', 'for', 'no', 'is', 'yes', 'im', 'u', '?', 'the', 'or',
  21. 'do', 'this', 'your', 'on', 'we', 'they', 'our', 'it', 'just', 'go', 'he', 'all', 'that',
  22. 'ur', 'who', 'of', 'can', 'its', 'get', 'cant', 'it\'s', 'can\'t', 'don\'t', 'i\'m', 'now',
  23. 'if', 'got', 'ss']
  24.  
  25. for i in xrange(range[0], range[1]):
  26.         if count == games:
  27.                 break
  28.        
  29.         os.system('cls')
  30.         print '%s/%s games analyzed' % (count, games)
  31.        
  32.         try:   
  33.                 request = urllib2.urlopen('http://euw.leagueoflegends.com/tribunal/en/get_reform_game/' + str(i) + '/1/')
  34.         except:
  35.                 continue
  36.                
  37.         data = request.read()
  38.        
  39.         if (data == ''):
  40.                 continue
  41.        
  42.         data = json.loads(data)
  43.        
  44.         for message in data['chat_log']:
  45.                 if message['association_to_offender'] == 'offender':
  46.                         words = message['message'].split()
  47.                        
  48.                         for word in words:
  49.                                 word = word.lower()
  50.                                 if not word.isdigit() and word not in exclude:
  51.                                         common_words[word] += 1
  52.        
  53.        
  54.  
  55.        
  56.         for player in data['players']:
  57.                 if player['association_to_offender'] == 'offender':
  58.                         common_champions[player['champion_name']] += 1
  59.                         break
  60.        
  61.         count += 1
  62.  
  63. common_words = sorted(common_words.iteritems(), key=operator.itemgetter(1), reverse=True)
  64. common_champions = sorted(common_champions.iteritems(), key=operator.itemgetter(1), reverse=True)
  65.  
  66. print 'Words used: ', len(common_words)
  67.  
  68. for i in xrange(30):
  69.         print common_words[i][0], ' - ', common_words[i][1]
  70.        
  71. print
  72. print
  73.  
  74. for i in xrange(30):
  75.         print common_champions[i][0], ' - ', common_champions[i][1]
clone this paste RAW Paste Data