Files
  • main.py
  • ouput.json
  • output-matrix.txt
  • pokemon-list.txt
  • pokemon-owned.txt
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import re
import json
import traceback

owned_list = [ ]

genders = [ '♂', '♀', 'G', '(?)' ]

pokemon_dict = {}

with open('pokemon-list.txt') as f:
        _pokemon = f.readlines()
        for p in _pokemon:
                parts = p.split(',')
                pokemon_dict[parts[1].lower().replace('\n', '')] = {
                        "number": int(parts[0]),
                        "name": parts[1].replace('\n', ''),
                        "colors": {
                                "normal": { "genders": [ 0, 0, 0, 0 ] },
                                "shiny": { "genders": [ 0, 0, 0, 0 ] },
                                "dark": { "genders": [ 0, 0, 0, 0 ] },
                                "golden": { "genders": [ 0, 0, 0, 0 ] }
                        }
                }

with open('pokemon-owned.txt') as f:
        owned_list = f.readlines()
        f.close()

print(len(owned_list))

for owned in owned_list:
        parts = re.split('\s', owned)
        pokemon = parts[0]
        
        gender = parts[1]

        if len(parts) == 4:
                gender = 'G'

        color = 'normal'
        name = ''
        broken_name = re.findall('[A-Z][^A-Z]*', pokemon)
        if len(broken_name) > 1:
                color = broken_name[0].lower()
                if len(broken_name) > 2:
                        name = ''.join(broken_name[1:len(broken_name)])
                else:
                        name = broken_name[1]
        else:
                name = broken_name[0]
        
        try:
                pokemon_dict[name.lower()]['colors'][color]['genders'][genders.index(gender)] += 1
        except Exception:
                # print(traceback.print_exc())
                pass

owned_matrix_list = []
to_own_count = 0
owned_count = 0
for i, p in enumerate(pokemon_dict):
        info = pokemon_dict[p]
        dex = info['number']
        name = info['name']

        c = ['_'] * 16
        count = 0
        for ci, color in enumerate(info['colors']):
                for gi, gender in enumerate(info['colors'][color]['genders']):
                        to_own_count += 1
                        if gender > 0:
                                c[count] = 'X'
                                owned_count += 1
                        count += 1

        owned_matrix = """
{dex} {name}
N:{c[0]}:{c[1]}:{c[2]}:{c[3]}
S:{c[4]}:{c[5]}:{c[6]}:{c[7]}
D:{c[8]}:{c[9]}:{c[10]}:{c[11]}
G:{c[12]}:{c[13]}:{c[14]}:{c[15]}
        """.format(**locals())

        owned_matrix_list.append(owned_matrix)

with open('ouput.json', 'w') as f:
        f.write(json.dumps(pokemon_dict))
        f.close()

with open('output-matrix.txt', 'w') as f:
        prepend_list = ["""
[b]Pokemon Owned:[/b] %s of %s
\n
[b]Completion: [/b]%s%%
\n
[code]\n""" % (owned_count, to_own_count, round((owned_count / to_own_count) * 100, 2))]

        owned_matrix_list = prepend_list + owned_matrix_list + [ '[/code]' ]
        f.writelines(owned_matrix_list)
        f.close()
        print("done")