-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.py
62 lines (44 loc) · 1.61 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from random import choice, sample
from version import random_version
CATEGORIES_DIR = os.path.join(os.path.dirname(__file__), 'categories')
def get_categories_shortlist():
return sample(list(CATEGORIES), 6)
def _load_category(filename):
category_name, _ = os.path.splitext(filename)
releases = []
generic_comments = []
with open(os.path.join(CATEGORIES_DIR, filename)) as cf:
for line in cf.readlines():
line = line.strip()
if not line:
continue
if line.startswith('>'):
content = line[1:].strip()
if not content:
raise RuntimeError(f'empty comment in {filename}')
if releases:
releases[-1]['comments'].append(content)
else:
print(filename)
generic_comments.append(content)
else:
releases.append({'name': line, 'comments': []})
return category_name, {
'releases': releases,
'generic_comments': generic_comments,
}
CATEGORIES = {name: category for name, category in (
_load_category(fn) for fn in os.listdir(CATEGORIES_DIR)
if not fn.startswith('.')
)}
if __name__ == '__main__':
shortlist = get_categories_shortlist()
for i, cat in enumerate(shortlist):
print(f'[{i + 1}] {cat}')
category = shortlist[int(input('pick a category!\n> ')) - 1]
product = choice(CATEGORIES[category]['releases'])['name']
print(
f'New release: {product}, version {random_version()}!'
'\n\nChanges include:\n\n>'
)