@jamezilla0/

PokemonVoyage - Noahs Ark

Python

No description

fork
loading
Files
  • main.py
  • ouput.json
  • output-matrix.txt
  • pokemon-list.txt
  • pokemon-owned.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.015951894521421428","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"CmltcG9ydCByZQppbXBvcnQganNvbgppbXBvcnQgdHJhY2ViYWNrCgpvd25lZF9saXN0ID0gWyBdCgpnZW5kZXJzID0gWyAn4pmCJywgJ+KZgCcsICdHJywgJyg/KScgXQoKcG9rZW1vbl9kaWN0ID0ge30KCndpdGggb3BlbigncG9rZW1vbi1saXN0LnR4dCcpIGFzIGY6CiAgICAgICAgX3Bva2Vtb24gPSBmLnJlYWRsaW5lcygpCiAgICAgICAgZm9yIHAgaW4gX3Bva2Vtb246CiAgICAgICAgICAgICAgICBwYXJ0cyA9IHAuc3BsaXQoJywnKQogICAgICAgICAgICAgICAgcG9rZW1vbl9kaWN0W3BhcnRzWzFdLmxvd2VyKCkucmVwbGFjZSgnXG4nLCAnJyldID0gewogICAgICAgICAgICAgICAgICAgICAgICAibnVtYmVyIjogaW50KHBhcnRzWzBdKSwKICAgICAgICAgICAgICAgICAgICAgICAgIm5hbWUiOiBwYXJ0c1sxXS5yZXBsYWNlKCdcbicsICcnKSwKICAgICAgICAgICAgICAgICAgICAgICAgImNvbG9ycyI6IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAibm9ybWFsIjogeyAiZ2VuZGVycyI6IFsgMCwgMCwgMCwgMCBdIH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInNoaW55IjogeyAiZ2VuZGVycyI6IFsgMCwgMCwgMCwgMCBdIH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImRhcmsiOiB7ICJnZW5kZXJzIjogWyAwLCAwLCAwLCAwIF0gfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiZ29sZGVuIjogeyAiZ2VuZGVycyI6IFsgMCwgMCwgMCwgMCBdIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQoKd2l0aCBvcGVuKCdwb2tlbW9uLW93bmVkLnR4dCcpIGFzIGY6CiAgICAgICAgb3duZWRfbGlzdCA9IGYucmVhZGxpbmVzKCkKICAgICAgICBmLmNsb3NlKCkKCnByaW50KGxlbihvd25lZF9saXN0KSkKCmZvciBvd25lZCBpbiBvd25lZF9saXN0OgogICAgICAgIHBhcnRzID0gcmUuc3BsaXQoJ1xzJywgb3duZWQpCiAgICAgICAgcG9rZW1vbiA9IHBhcnRzWzBdCiAgICAgICAgCiAgICAgICAgZ2VuZGVyID0gcGFydHNbMV0KCiAgICAgICAgaWYgbGVuKHBhcnRzKSA9PSA0OgogICAgICAgICAgICAgICAgZ2VuZGVyID0gJ0cnCgogICAgICAgIGNvbG9yID0gJ25vcm1hbCcKICAgICAgICBuYW1lID0gJycKICAgICAgICBicm9rZW5fbmFtZSA9IHJlLmZpbmRhbGwoJ1tBLVpdW15BLVpdKicsIHBva2Vtb24pCiAgICAgICAgaWYgbGVuKGJyb2tlbl9uYW1lKSA+IDE6CiAgICAgICAgICAgICAgICBjb2xvciA9IGJyb2tlbl9uYW1lWzBdLmxvd2VyKCkKICAgICAgICAgICAgICAgIGlmIGxlbihicm9rZW5fbmFtZSkgPiAyOgogICAgICAgICAgICAgICAgICAgICAgICBuYW1lID0gJycuam9pbihicm9rZW5fbmFtZVsxOmxlbihicm9rZW5fbmFtZSldKQogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICAgICAgbmFtZSA9IGJyb2tlbl9uYW1lWzFdCiAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgIG5hbWUgPSBicm9rZW5fbmFtZVswXQogICAgICAgIAogICAgICAgIHRyeToKICAgICAgICAgICAgICAgIHBva2Vtb25fZGljdFtuYW1lLmxvd2VyKCldWydjb2xvcnMnXVtjb2xvcl1bJ2dlbmRlcnMnXVtnZW5kZXJzLmluZGV4KGdlbmRlcildICs9IDEKICAgICAgICBleGNlcHQgRXhjZXB0aW9uOgogICAgICAgICAgICAgICAgIyBwcmludCh0cmFjZWJhY2sucHJpbnRfZXhjKCkpCiAgICAgICAgICAgICAgICBwYXNzCgpvd25lZF9tYXRyaXhfbGlzdCA9IFtdCnRvX293bl9jb3VudCA9IDAKb3duZWRfY291bnQgPSAwCmZvciBpLCBwIGluIGVudW1lcmF0ZShwb2tlbW9uX2RpY3QpOgogICAgICAgIGluZm8gPSBwb2tlbW9uX2RpY3RbcF0KICAgICAgICBkZXggPSBpbmZvWydudW1iZXInXQogICAgICAgIG5hbWUgPSBpbmZvWyduYW1lJ10KCiAgICAgICAgYyA9IFsnXyddICogMTYKICAgICAgICBjb3VudCA9IDAKICAgICAgICBmb3IgY2ksIGNvbG9yIGluIGVudW1lcmF0ZShpbmZvWydjb2xvcnMnXSk6CiAgICAgICAgICAgICAgICBmb3IgZ2ksIGdlbmRlciBpbiBlbnVtZXJhdGUoaW5mb1snY29sb3JzJ11bY29sb3JdWydnZW5kZXJzJ10pOgogICAgICAgICAgICAgICAgICAgICAgICB0b19vd25fY291bnQgKz0gMQogICAgICAgICAgICAgICAgICAgICAgICBpZiBnZW5kZXIgPiAwOgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNbY291bnRdID0gJ1gnCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3duZWRfY291bnQgKz0gMQogICAgICAgICAgICAgICAgICAgICAgICBjb3VudCArPSAxCgogICAgICAgIG93bmVkX21hdHJpeCA9ICIiIgp7ZGV4fSB7bmFtZX0KTjp7Y1swXX06e2NbMV19OntjWzJdfTp7Y1szXX0KUzp7Y1s0XX06e2NbNV19OntjWzZdfTp7Y1s3XX0KRDp7Y1s4XX06e2NbOV19OntjWzEwXX06e2NbMTFdfQpHOntjWzEyXX06e2NbMTNdfTp7Y1sxNF19OntjWzE1XX0KICAgICAgICAiIiIuZm9ybWF0KCoqbG9jYWxzKCkpCgogICAgICAgIG93bmVkX21hdHJpeF9saXN0LmFwcGVuZChvd25lZF9tYXRyaXgpCgp3aXRoIG9wZW4oJ291cHV0Lmpzb24nLCAndycpIGFzIGY6CiAgICAgICAgZi53cml0ZShqc29uLmR1bXBzKHBva2Vtb25fZGljdCkpCiAgICAgICAgZi5jbG9zZSgpCgp3aXRoIG9wZW4oJ291dHB1dC1tYXRyaXgudHh0JywgJ3cnKSBhcyBmOgogICAgICAgIHByZXBlbmRfbGlzdCA9IFsiIiIKW2JdUG9rZW1vbiBPd25lZDpbL2JdICVzIG9mICVzClxuCltiXUNvbXBsZXRpb246IFsvYl0lcyUlClxuCltjb2RlXVxuIiIiICUgKG93bmVkX2NvdW50LCB0b19vd25fY291bnQsIHJvdW5kKChvd25lZF9jb3VudCAvIHRvX293bl9jb3VudCkgKiAxMDAsIDIpKV0KCiAgICAgICAgb3duZWRfbWF0cml4X2xpc3QgPSBwcmVwZW5kX2xpc3QgKyBvd25lZF9tYXRyaXhfbGlzdCArIFsgJ1svY29kZV0nIF0KICAgICAgICBmLndyaXRlbGluZXMob3duZWRfbWF0cml4X2xpc3QpCiAgICAgICAgZi5jbG9zZSgpCiAgICAgICAgcHJpbnQoImRvbmUiKQ=="},"asBuffer":null},"loaded":true}}
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")