View difference between Paste ID: SPDxud0c and GmVy8Uhi
SHOW: | | - or go back to the newest paste.
1
# -*- coding: utf-8 -*-
2
 
3-
import urllib2
3+
import urllib.request
4
import json
5
import operator
6
import os
7
from collections import defaultdict
8
from multiprocessing.dummy import Pool
9
import threading
10
 
11
class Counter:
12-
range = [860000, 970000]
12+
    def __init__(self, i=0):
13
        self.i = i
14-
count = 0
14+
        # create a lock
15
        self.lock = threading.Lock()
16
17
    def __iter__(self):
18
        return self
19-
exclude = ['a', 'i', 'me', 'why', 'to', 'and', 'my', 'you', 'dont', 'with', 'what', 'in', 
19+
20
    def next(self):
21-
'do', 'this', 'your', 'on', 'we', 'they', 'our', 'it', 'just', 'go', 'he', 'all', 'that', 
21+
        # acquire/release the lock when updating self.i
22-
'ur', 'who', 'of', 'can', 'its', 'get', 'cant', 'it\'s', 'can\'t', 'don\'t', 'i\'m', 'now', 
22+
        with self.lock:
23
            self.i += 1
24
            return self.i
25-
for i in xrange(range[0], range[1]):
25+
    
26-
	if count == games:
26+
    def current(self):
27-
		break
27+
        return self.i
28-
	
28+
 
29-
	os.system('cls')
29+
30-
	print '%s/%s games analyzed' % (count, games)
30+
 
31-
	
31+
worker_pool_size = 20
32-
	try:	
32+
worker_pool = Pool(worker_pool_size)
33-
		request = urllib2.urlopen('http://euw.leagueoflegends.com/tribunal/en/get_reform_game/' + str(i) + '/1/')
33+
 
34-
	except:
34+
35-
		continue
35+
game_range = [860000, 970000]
36-
		
36+
 
37-
	data = request.read()
37+
counter = Counter()
38-
	
38+
 
39-
	if (data == ''):
39+
chunk_size = 3
40-
		continue
40+
41-
	
41+
42-
	data = json.loads(data)
42+
43-
	
43+
 
44-
	for message in data['chat_log']:
44+
exclude = ['a', 'i', 'me', 'why', 'to', 'and', 'my', 'you', 'dont', 'with', 'what', 'in',
45-
		if message['association_to_offender'] == 'offender':
45+
46-
			words = message['message'].split()
46+
'do', 'this', 'your', 'on', 'we', 'they', 'our', 'it', 'just', 'go', 'he', 'all', 'that',
47-
			
47+
'ur', 'who', 'of', 'can', 'its', 'get', 'cant', 'it\'s', 'can\'t', 'don\'t', 'i\'m', 'now',
48-
			for word in words:
48+
49-
				word = word.lower()
49+
 
50-
				if not word.isdigit() and word not in exclude:
50+
51-
					common_words[word] += 1
51+
def loading_logic(i):
52-
	
52+
    if counter.current() >= games:
53-
	
53+
        return
54
    
55-
	
55+
    try:
56-
	for player in data['players']:
56+
        request = urllib.request.urlopen('http://euw.leagueoflegends.com/tribunal/en/get_reform_game/' + str(i) + '/1/')
57-
		if player['association_to_offender'] == 'offender':
57+
    except:
58-
			common_champions[player['champion_name']] += 1
58+
        return
59-
			break
59+
           
60-
	
60+
    data = request.read()
61-
	count += 1
61+
    data = data.decode('utf-8')
62
   
63-
common_words = sorted(common_words.iteritems(), key=operator.itemgetter(1), reverse=True)
63+
    if (data == ''):
64-
common_champions = sorted(common_champions.iteritems(), key=operator.itemgetter(1), reverse=True)
64+
        return
65
   
66-
print 'Words used: ', len(common_words)
66+
    data = json.loads(data)
67
   
68-
for i in xrange(30):
68+
    for message in data['chat_log']:
69-
	print common_words[i][0], ' - ', common_words[i][1]
69+
        if message['association_to_offender'] == 'offender':
70-
	
70+
            words = message['message'].split()
71-
print 
71+
           
72-
print
72+
            for word in words:
73
                word = word.lower()
74-
for i in xrange(30):
74+
                if not word.isdigit() and word not in exclude:
75-
	print common_champions[i][0], ' - ', common_champions[i][1]
75+
                    common_words[word] += 1
76
   
77
    for player in data['players']:
78
        if player['association_to_offender'] == 'offender':
79
            common_champions[player['champion_name']] += 1
80
            break
81
   
82
    counter.next()
83
84
85
for i in range(game_range[0], game_range[1], worker_pool_size*chunk_size):
86
    os.system('cls')
87
    print('%s/%s games analyzed' % (counter.current(), games))
88
    worker_pool.map(loading_logic, range(i, i+worker_pool_size*chunk_size))
89
    if counter.current() >= games:
90
        break
91
92
 
93
common_words = sorted(common_words.items(), key=operator.itemgetter(1), reverse=True)
94
common_champions = sorted(common_champions.items(), key=operator.itemgetter(1), reverse=True)
95
 
96
print('Words used: ', len(common_words))
97
 
98
for i in range(30):
99
    print(common_words[i][0], ' - ', common_words[i][1])
100
       
101
print()
102
print()
103
 
104
for i in range(30):
105
        print(common_champions[i][0], ' - ', common_champions[i][1])