Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_army_link not working due to mismatched IDs #212

Closed
btimothy-har opened this issue Oct 1, 2023 · 1 comment
Closed

parse_army_link not working due to mismatched IDs #212

btimothy-har opened this issue Oct 1, 2023 · 1 comment

Comments

@btimothy-har
Copy link

btimothy-har commented Oct 1, 2023

There's a mismatch between the IDs used for parse_army_link and the ones in _troop_holder.

Link used for below examples: https://link.clashofclans.com/en?action=CopyArmy&army=u3x58-5x1
(3x Ice Golems + 5x Barbarian)

The utils.parse_army_link function:

ARMY_LINK_SEPERATOR = re.compile(r"u(?P<units>[\d+x-]+)|s(?P<spells>[\d+x-]+)")

def parse_army_link(link: str) -> Tuple[List[Tuple[int, int]], List[Tuple[int, int]]]:
    matches = ARMY_LINK_SEPERATOR.finditer(link)

    units, spells = [], []
    for match in matches:
        if match.group("units"):
            units = [
                (4_000_000 + int(split[1]), int(split[0]))
                for split in (troop.split('x') for troop in match.group("units").split('-'))
            ]
        elif match.group("spells"):
            spells = [
                (26_000_000 + int(split[1]), int(split[0]))
                for split in (spell.split('x') for spell in match.group("spells").split('-'))
            ]

    return units, spells

parsed_cc = parse_army_link(link)

Returns:
([(4000058, 3), (4000001, 5)], [])

But doing:

for i in coc_client._troop_holder.items:
   print(f"{i.id} {i.name}

Returns:

1000 Barbarian
1044 Ice Golem

So it looks like the IDs used in _troop_holder don't line up to the ones used by army URLs.

@lukasthaler
Copy link
Collaborator

Fixed in #214 (16528a5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants