|
3 | 3 | import random
|
4 | 4 | import re
|
5 | 5 | import json
|
| 6 | +from typing import Dict, List |
6 | 7 |
|
7 | 8 | try:
|
8 | 9 | from hashlib import md5
|
|
24 | 25 |
|
25 | 26 | humans_file = os.path.join(os.path.dirname(__file__), 'static', 'humans.txt')
|
26 | 27 | messages_file = os.path.join(os.path.dirname(__file__), 'commit_messages.txt')
|
27 |
| -messages = {} |
| 28 | +messages: Dict[str, str] = {} |
28 | 29 |
|
29 | 30 | # Create a hash table of all commit messages
|
30 |
| -with open(messages_file) as messages_input: |
| 31 | +with open(messages_file, 'r', encoding='utf-8') as messages_input: |
31 | 32 | for line in messages_input.readlines():
|
32 |
| - messages[md5(line).hexdigest()] = line |
| 33 | + messages[md5(line.encode('utf-8')).hexdigest()] = line |
33 | 34 |
|
34 |
| -with open(humans_file) as humans_input: |
| 35 | +names: List[str] = [] |
| 36 | + |
| 37 | +with open(humans_file, 'r', encoding='utf-8') as humans_input: |
35 | 38 | humans_content = humans_input.read()
|
36 | 39 | for line in humans_content.split("\n"):
|
37 | 40 | if "Name:" in line:
|
|
41 | 44 | else:
|
42 | 45 | names.append(data.split(" ")[0])
|
43 | 46 |
|
| 47 | +print(names) |
| 48 | + |
44 | 49 | num_re = re.compile(r"XNUM([0-9,]*)X")
|
45 | 50 |
|
46 | 51 | def fill_line(message):
|
@@ -76,7 +81,7 @@ def fill_line(message):
|
76 | 81 | class MainHandler(tornado.web.RequestHandler):
|
77 | 82 | def get(self, message_hash=None):
|
78 | 83 | if not message_hash:
|
79 |
| - message_hash = random.choice(messages.keys()) |
| 84 | + message_hash = random.choice(list(messages.keys())) |
80 | 85 | elif message_hash not in messages:
|
81 | 86 | raise tornado.web.HTTPError(404)
|
82 | 87 |
|
|
0 commit comments