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

TEST #259

Closed
wants to merge 248 commits into from
Closed

TEST #259

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
248 commits
Select commit Hold shift + click to select a range
320bfa0
make __eq__ functions make more sense
Kuchenmampfer Mar 17, 2023
6d68480
add clan_tag to `RaidLogEntry` and fix `__eq__`
Kuchenmampfer Mar 18, 2023
a765cfe
Update troop.py
MagicTheDev Mar 18, 2023
22529e8
correct input parameter of repr
Kuchenmampfer Mar 30, 2023
dd92ebf
document PlayerHouseElements
Kuchenmampfer May 1, 2023
555f040
Add stars to make sure the attack is the same!
doluk May 12, 2023
a97933a
Merge pull request #186 from mathsman5133/better_eq_on_raid_classes
doluk May 12, 2023
e30a701
Update hero.py
doluk May 12, 2023
e126802
Merge pull request #187 from mathsman5133/MagicTheDev-patch-1
doluk May 12, 2023
33f849b
Remove depreciated login methods
doluk May 12, 2023
2806d53
Bump version number
doluk May 12, 2023
5ed489c
add new endpoints and rename old ones
doluk May 12, 2023
2d01b37
remove depreciated methods from import
doluk May 12, 2023
72f6cb9
Update versus to builder base
doluk May 12, 2023
7f0a8e3
Merge pull request #192 from mathsman5133/get_current_war_fix
Kuchenmampfer May 14, 2023
b6e1cb4
Update changelog
doluk May 14, 2023
d2ea526
Merge pull request #193 from mathsman5133/g8_2.4.0_candidate
Kuchenmampfer May 14, 2023
fccda7e
Fix pyproject.toml
doluk May 14, 2023
76ebeb9
Add triggers extension to pyproject.toml
doluk May 14, 2023
d5f0ef7
Merge pull request #194 from mathsman5133/doluk-patch-1
Kuchenmampfer May 14, 2023
3219ead
rename logs
Kuchenmampfer May 16, 2023
7203062
Fix bug causing old keys to be ignored.
doluk May 17, 2023
072b819
Append keys properly to key list
doluk May 17, 2023
8c5c797
Fix ClanEvents.member_count
doluk May 17, 2023
8cc8950
Merge remote-tracking branch 'cocpy_main/g8_2.4.0_candidate' into g8_…
Kuchenmampfer May 18, 2023
0136089
bump version numbers and add changelog
Kuchenmampfer May 18, 2023
c9d9509
re add event fix
Kuchenmampfer May 18, 2023
e019f67
correct changelog
Kuchenmampfer May 18, 2023
26c2aba
Merge pull request #195 from mathsman5133/g8_2.4.0_candidate
Kuchenmampfer May 18, 2023
98fc7d7
fix typo
Kuchenmampfer May 19, 2023
258b6da
Add new mock data for clans
doluk May 29, 2023
c40d1e9
added default values for warTies, warLoses to deal with search clans …
doluk May 29, 2023
7646549
Write full tests for all attributes given directly by the api
doluk May 29, 2023
9044c35
Add clantag to mock data
doluk May 29, 2023
6cdf9e8
Write a full test for raid seasons
doluk May 29, 2023
cbb7e6d
Start migrating_to_v3.rst
doluk May 29, 2023
186f734
Add changelog entry
doluk May 29, 2023
941e297
Extend raidseason tests to cover all properties coc.py supports
doluk May 29, 2023
30d8d25
fix missing attribute _cs_raid_attacks
doluk May 29, 2023
657d61b
Merge branch 'master' into g10_3.0.0
Kuchenmampfer May 30, 2023
4c0a0da
Merge remote-tracking branch 'cocpy_main/g10_3.0.0' into g10_3.0.0
Kuchenmampfer May 30, 2023
425f8f9
bump version
Kuchenmampfer May 30, 2023
f7e3daf
Fix cache interaction with non 200 responses
doluk Jun 5, 2023
29ee837
Error with error code without response
doluk Jun 5, 2023
1259b2a
remove expired key
doluk Jun 5, 2023
6fb561e
fix missing attribute _cs_raid_attacks
doluk May 29, 2023
3792e81
bump version
Kuchenmampfer Jun 6, 2023
f291adc
Revamp mock data to a more non python approach, Update tests to still…
doluk Jun 6, 2023
1c26f96
Merge pull request #200 from mathsman5133/port_raid_fix_to_master
doluk Jun 6, 2023
bdf2b51
Merge pull request #199 from mathsman5133/cache_fix
doluk Jun 6, 2023
55b2fc2
New Static Files & Rework
Magic-Jr Jun 20, 2023
73eeb17
remove print
Magic-Jr Jun 20, 2023
6fb49ed
Update __init__.py
Magic-Jr Jun 20, 2023
2fc66c4
Update pyproject.toml
Magic-Jr Jun 20, 2023
583ada9
Merge pull request #204 from Magic-Jr/master
doluk Jun 20, 2023
7eee8fb
clean up object ids
doluk Jun 22, 2023
20d0c20
clean up object ids
doluk Jun 22, 2023
6baa5a2
update examples
doluk Jun 22, 2023
c84050e
add builder base league
doluk Jun 22, 2023
e08d8dc
add player house elements at correct base class level
doluk Jun 22, 2023
dba3006
update requirements.txt for new static file origin
doluk Jun 22, 2023
6b14ada
remove versus trophies test
doluk Jun 22, 2023
51ffce9
remove object ids dependency
doluk Jun 22, 2023
37121ae
add blank line at file end
doluk Jun 22, 2023
6f420d4
add doluk as maintainer
doluk Jun 22, 2023
f8fd5d8
Fix BuilderBaseLeague
doluk Jun 22, 2023
eddfb8e
add BuilderBaseLeague
doluk Jun 22, 2023
e782f92
bump version
doluk Jun 22, 2023
03edd8f
prevent circular import
doluk Jun 22, 2023
e615898
Fix typo's!
GustavoSchip Jun 23, 2023
1dfd8e0
Another typo fixed!
GustavoSchip Jun 23, 2023
189aba6
Add stars property to RaidDistricts
doluk Jul 11, 2023
269e26a
add builder base league endpoints to client
Kuchenmampfer Jul 11, 2023
b44212b
rename the hopefully last internal xxxlogs to xxx_logs
Kuchenmampfer Jul 11, 2023
f75939a
remove incorrect documentation
Kuchenmampfer Jul 11, 2023
d378fb3
add back triggers extension that somehow got lost in the weeds
Kuchenmampfer Jul 11, 2023
abc2a95
write migration guide
Kuchenmampfer Jul 11, 2023
0c83742
improve migration guide and include it in the docs
Kuchenmampfer Jul 11, 2023
3acf162
Rewrite League and BaseLeague, fix Player.get_pet()
doluk Jul 12, 2023
18eaf38
Add example for importing a client from one file everywhere
doluk Jul 12, 2023
c4285a0
Add new example to docs
doluk Jul 12, 2023
251508c
finish up the migration guide and put *something* into the acknowledg…
Kuchenmampfer Jul 12, 2023
94cde6a
Merge pull request #208 from mathsman5133/g10_3.0.0
Kuchenmampfer Jul 12, 2023
4a2cc3b
Merge pull request #205 from GustavoSchip/patch-2
Kuchenmampfer Jul 12, 2023
88b91ca
rename troop_meta to json_meta
lukasthaler Dec 15, 2023
86c4a18
chore: update static files
lukasthaler Dec 15, 2023
e39c80e
fix: ignore deprecated content
lukasthaler Dec 15, 2023
e4febdb
feature: add hero equipment
lukasthaler Dec 15, 2023
882db83
chore: add root rider and spirit fox
lukasthaler Dec 15, 2023
37a358c
feature: add th level to ClanMember
lukasthaler Dec 15, 2023
3a81e54
fix: troop and hero change events misfiring (#218)
lukasthaler Dec 18, 2023
eafb0a1
ensure DataContainer hash is static
lukasthaler Dec 18, 2023
16528a5
fix: army link parser
lukasthaler Dec 18, 2023
50c4010
fix hero hash
lukasthaler Dec 18, 2023
63e4315
update clan example to include th level
lukasthaler Dec 18, 2023
0dcc4d0
Merge pull request #214 from mathsman5133/feature/th16-content
lukasthaler Dec 19, 2023
22e49a2
release v3.1.0
lukasthaler Dec 19, 2023
ff93103
Merge pull request #219 from mathsman5133/release/v3.1.0
MagicTheDev Dec 19, 2023
c19b976
fix: readthedocs build config
lukasthaler Dec 19, 2023
0e5ee90
Merge pull request #220 from mathsman5133/fix/readthedocs-build
MagicTheDev Dec 19, 2023
6390c3a
chore: make equipment class importable
lukasthaler Dec 19, 2023
e4bfbb4
feature: add custom class support for war-related entities
lukasthaler Dec 19, 2023
e56fbec
release v3.2.0
lukasthaler Dec 19, 2023
5e51714
Merge pull request #221 from mathsman5133/feature/custom-classes
MagicTheDev Dec 19, 2023
d675ed6
fix: month overflow in cg start/end
lukasthaler Dec 28, 2023
a4ff5c0
fix: spell lookup needs village flag
lukasthaler Dec 28, 2023
d56c613
release v3.2.1
lukasthaler Dec 28, 2023
b6da3ff
Merge pull request #223 from mathsman5133/fix/3.2.1
lukasthaler Dec 28, 2023
5aa4039
Root Rider set as elixir troop (instead of dark elixir troop)
rreemmii-dev Dec 29, 2023
62da514
Merge pull request #224 from rreemmii-dev/patch-1
lukasthaler Feb 21, 2024
fb9c691
feature: split troops/spells by resource
lukasthaler Feb 27, 2024
518e356
chore: add new spells and equipment
lukasthaler Feb 27, 2024
8c7d6a0
chore: bump versions & add release notes
lukasthaler Feb 27, 2024
e2dfabc
chore: update static data
lukasthaler Feb 29, 2024
8eb2142
Merge pull request #226 from mathsman5133/february-update
lukasthaler Feb 29, 2024
31128bb
fix: catch&raise stray response HTTP status codes
lukasthaler Mar 1, 2024
50258e0
chore: version bump & release notes
lukasthaler Mar 1, 2024
8daa016
Merge pull request #227 from mathsman5133/fix/http-error
doluk Mar 1, 2024
66de793
Update workflow pushing to PyPi
mathsman5133 Mar 3, 2024
9d9dd9c
Add workflow_dispatch to manually trigger push to PyPi
mathsman5133 Mar 3, 2024
8f7f358
add back in checkout actions and use build instead of setuptools
mathsman5133 Mar 3, 2024
8e539b0
make warning a bit more clear and add checkbox
mathsman5133 Mar 3, 2024
047ac02
don't run flow if confirmation fails
mathsman5133 Mar 3, 2024
d0838ef
use false string in comparison
mathsman5133 Mar 3, 2024
9686154
chore: docs updates
lukasthaler Mar 14, 2024
10e4f58
fix: add equipment to static data updater
lukasthaler Mar 14, 2024
b4f837e
chore: update static data
lukasthaler Mar 14, 2024
4b27a9c
chore: add fireball equipment
lukasthaler Mar 14, 2024
0001312
chore: version bump & changelog
lukasthaler Mar 14, 2024
4d41ad8
Merge pull request #228 from mathsman5133/workflow-testing
lukasthaler Mar 14, 2024
721d19e
Merge pull request #229 from mathsman5133/fix/3.4.0
doluk Mar 14, 2024
cb50fd3
Delete docs/extensions/discord_links.rst
doluk Mar 27, 2024
dfe1cb0
Delete examples/discord_links.py
doluk Mar 27, 2024
ea67b93
Remove links api tests
doluk Mar 27, 2024
290302f
Remove discord_links
doluk Mar 27, 2024
bb660ad
chore: add missing achievements
lukasthaler Mar 31, 2024
c9f2bcd
Merge pull request #230 from mathsman5133/remove_links_api_docs
doluk Mar 31, 2024
fa21f7c
Merge pull request #231 from mathsman5133/chore/add-achievements
lukasthaler Mar 31, 2024
57ef269
feature: add a function to get the fingerprint
lukasthaler Mar 31, 2024
982df55
chore: manually update static data for balance patch
lukasthaler Mar 31, 2024
a1e4518
release v3.4.1
lukasthaler Mar 31, 2024
3d5d979
fix: troop json
lukasthaler Mar 31, 2024
2dd3c98
Merge pull request #232 from mathsman5133/feature/static-data-hash
lukasthaler Mar 31, 2024
6e3aed0
chore: add angry jelly pet
lukasthaler Apr 20, 2024
703f7c0
chore: update static data
lukasthaler Apr 20, 2024
44c8585
bump versions & add changelog
lukasthaler Apr 20, 2024
898ea49
Merge pull request #233 from mathsman5133/april-2024-update
lukasthaler Apr 20, 2024
4433b73
add base url feature
doluk Apr 27, 2024
61bc887
move town hall level properly to clanmember
doluk Apr 27, 2024
1be1f22
Add events for equipment
doluk Apr 27, 2024
93760d7
Fix renamed builder base attributes. Keep old ones due to breaking ch…
doluk Apr 27, 2024
81c33b4
Update events example with the builder base renaming
doluk Apr 27, 2024
4251b73
Update docs
doluk Apr 27, 2024
aeeb730
Update version
doluk Apr 27, 2024
46d66bd
Merge pull request #235 from mathsman5133/base_url+event-equipement
doluk Apr 27, 2024
ba7c06d
bump version to 3.5.2
doluk Apr 27, 2024
dfcb7dc
bump version to 3.5.2
doluk Apr 27, 2024
3e9d95b
Merge pull request #236 from mathsman5133/v3.5.2
doluk Apr 27, 2024
c311606
add fallbacks to icon/badge URLs
lukasthaler May 14, 2024
68813db
version bump & changelog
lukasthaler May 14, 2024
05fb797
fix: season endpoints typings, defaults & docstrings
lukasthaler May 14, 2024
ce76d35
update changelog
lukasthaler May 14, 2024
a477898
Merge pull request #237 from mathsman5133/fix/icon-url
lukasthaler May 14, 2024
a755613
Fix docs
doluk May 17, 2024
261f553
Add the logic to manually overwrite the ip used to create new keys
doluk May 17, 2024
a96298b
Update changelog.rst
doluk May 17, 2024
9711b3b
Bump version number
doluk May 17, 2024
d9b7ac5
Prevent unnecessary decoding
doluk May 17, 2024
f14c462
Fix typo in changelog entry
doluk May 17, 2024
e7a3528
Bump version even further
doluk May 17, 2024
e72a313
Merge pull request #238 from mathsman5133/3.5.4
lukasthaler May 17, 2024
59c1ec1
added show inheritance property in all models
Anubhav1603 Jun 2, 2024
46827e0
removed inheritance of base class if its just showing object
Anubhav1603 Jun 2, 2024
e30afef
removed inheritance of base class of war,raid,etc if its just showing…
Anubhav1603 Jun 2, 2024
e4a77e6
removed inheritance of data container inheriting class
Anubhav1603 Jun 2, 2024
cac321c
made new line more consistent and removed one extra indendent
Anubhav1603 Jun 2, 2024
1d7f189
Merge pull request #239 from Anubhav1603/master
doluk Jun 2, 2024
cacd69d
Bump version number
doluk Jun 2, 2024
56988a4
Update static data according to https://supercell.com/en/games/clasho…
doluk Jun 3, 2024
73a41a3
Add battle_modifier and enums for battle modifier, war state. Declutt…
doluk Jun 17, 2024
72017e3
Update changelog and add new equipment and troop
doluk Jun 17, 2024
5cd0318
feature: add battle modifier to ClanWarLogEntry
lukasthaler Jun 17, 2024
dbac2c9
feature: make war result an enum
lukasthaler Jun 17, 2024
82b163c
chore: version bump & docs update
lukasthaler Jun 17, 2024
fd531cb
fix: ExtendedEnum.in_game_name can't use self in lookup
lukasthaler Jun 17, 2024
b2c1268
fix: make try_enum work with ExtendedEnum
lukasthaler Jun 17, 2024
accdd30
chore: default battle modifier to BattleModifier.none
lukasthaler Jun 17, 2024
38a2fb9
fix: battle modifier values are lowercase
lukasthaler Jun 17, 2024
41cfcd9
Detect already decompressed files and don't try to decompress them ag…
doluk Jun 17, 2024
1b972b4
Merge remote-tracking branch 'origin/3.6.1' into 3.6.1
doluk Jun 17, 2024
6251e48
Update static data
doluk Jun 17, 2024
abd83d0
Update static data
doluk Jun 17, 2024
5775dc3
Update static data
doluk Jun 17, 2024
6dbb043
Merge pull request #240 from mathsman5133/3.6.1
lukasthaler Jun 17, 2024
542fec4
added magic mirror to equipments
Anubhav1603 Aug 13, 2024
2be04a9
Merge pull request #243 from Anubhav1603/master
lukasthaler Aug 13, 2024
2c18bc2
chore: update static data
lukasthaler Aug 13, 2024
70ec6d6
fix: ensure dict when querying with empty tag
lukasthaler Aug 13, 2024
c0d331b
chore: version bumps & docs
lukasthaler Aug 13, 2024
6e77203
Merge pull request #244 from mathsman5133/release/3.7.1
lukasthaler Aug 13, 2024
1446b3d
Enable gzip, deflate compression (#246)
doluk Sep 12, 2024
f42dba5
updated static updater to use the "dynamic" way of getting fingerprin…
MagicTheDev Nov 26, 2024
be9fb17
added new troop ids
MagicTheDev Nov 26, 2024
e874403
added new spell ids
MagicTheDev Nov 26, 2024
8dace18
update enums w/ new troop, spell, hero, & equipment
MagicTheDev Nov 26, 2024
b39d6ad
new static files
MagicTheDev Nov 26, 2024
88d1c49
Ignore cache for verify token endpoint
mathsman5133 Dec 6, 2024
a1e6965
Don't pass ignore_cache to aiohttp request
mathsman5133 Dec 6, 2024
ef5a1d2
Generalize cls definitions to be supported by every client api call. …
doluk Dec 8, 2024
5c5b5a5
Point cls to newly introduced object_cls
doluk Dec 8, 2024
1ec875e
Typedef fix
doluk Dec 8, 2024
f4b5a24
Fix Typing
doluk Dec 8, 2024
2798e80
new static files
MagicTheDev Dec 22, 2024
462ae4b
new static files parsing
MagicTheDev Dec 22, 2024
140d4de
update json loaders to accomodate the new json based static files, wh…
MagicTheDev Dec 22, 2024
f3d924d
change to order of unlocking
MagicTheDev Dec 22, 2024
3bf3c9b
add lavaloon puppet
MagicTheDev Dec 22, 2024
c426c01
version change
MagicTheDev Dec 22, 2024
d9e9b86
cleanup
MagicTheDev Dec 23, 2024
17288a8
new version
MagicTheDev Dec 23, 2024
b6e5f41
added get_equipment
MagicTheDev Dec 23, 2024
d4b94d7
added get_equipment
MagicTheDev Dec 23, 2024
f6ef01d
fix hv & bb baby dragon swap
MagicTheDev Dec 23, 2024
059c156
fix super troops
MagicTheDev Dec 23, 2024
1f7884a
training cost no longer exists, and training time is constant
MagicTheDev Dec 23, 2024
567ad8e
training cost no longer exists, and training time is constant
MagicTheDev Dec 23, 2024
f125334
fix get_equipment, continued
MagicTheDev Dec 23, 2024
dd5615b
Update enums.py
MagicTheDev Dec 23, 2024
fe5fa42
Merge pull request #251 from mathsman5133/current_war_index_error
MagicTheDev Jan 1, 2025
e53c709
fix imports
MagicTheDev Jan 1, 2025
e0d1ea8
remove import
MagicTheDev Jan 1, 2025
8360556
remove walrus operator
MagicTheDev Jan 1, 2025
d90b10f
remove space
MagicTheDev Jan 1, 2025
ba0324c
Merge branch 'master' into th17
MagicTheDev Jan 1, 2025
3ea5b92
update changelog
MagicTheDev Jan 1, 2025
acad7e9
Merge remote-tracking branch 'origin/th17' into th17
MagicTheDev Jan 1, 2025
67c2cc7
update changelog
MagicTheDev Jan 2, 2025
eaad195
update changelog
MagicTheDev Jan 2, 2025
31d5e23
update changelog
MagicTheDev Jan 2, 2025
c5b7c19
update changelog
MagicTheDev Jan 2, 2025
fe291d4
Merge pull request #248 from mathsman5133/th17
MagicTheDev Jan 2, 2025
6292b43
Update conf.py
doluk Jan 2, 2025
5b6772c
Merge pull request #253 from mathsman5133/doluk-patch-2
MagicTheDev Jan 2, 2025
12db1c8
Kwargs Fix (#254)
MagicTheDev Jan 4, 2025
6424c4a
fix: remove comparison, always is true
MagicTheDev Jan 6, 2025
d109cfe
chore: update version to 3.8.2
MagicTheDev Jan 6, 2025
25c2bc3
docs: update changelog
MagicTheDev Jan 6, 2025
f36b4b5
Merge pull request #257 from mathsman5133/fix/current-war
MagicTheDev Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions .github/workflows/push-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
on:
workflow_dispatch:
inputs:
confirmation:
description: 'I want to manually trigger a PyPi push, without publishing a GitHub release (not recommended!)'
required: true
type: boolean
release:
types: [created]

jobs:
deploy:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/coc.py
permissions:
id-token: write
if: github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && github.event.inputs.confirmation != 'false')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
pip install --upgrade pip
pip install --upgrade build
- name: Build
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ jobs:
DEV_SITE_EMAIL: ${{ secrets.DEV_SITE_EMAIL }}
DEV_SITE_PASSWORD: ${{ secrets.DEV_SITE_PASSWORD }}
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
LINKS_API_USERNAME: ${{ secrets.LINKS_API_USERNAME }}
LINKS_API_PASSWORD: ${{ secrets.LINKS_API_PASSWORD }}
RUNNING_TESTS: true
run: |
python -m examples.discord_links
python -m examples.events_example
python -m examples.war_logs
5 changes: 3 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ version: 2
formats: []

build:
image: latest
os: ubuntu-22.04
tools:
python: "3.7"

sphinx:
configuration: docs/conf.py
fail_on_warning: false
builder: html

python:
version: 3.7
install:
- method: pip
path: .
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This example will get a player with a certain tag, and search for 5 clans with a
async with coc.Client() as coc_client:
try:
await coc_client.login("email", "password")
except coc.invalidcredentials as error:
except coc.InvalidCredentials as error:
exit(error)

player = await coc_client.get_player("tag")
Expand Down
13 changes: 9 additions & 4 deletions coc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@
SOFTWARE.
"""

__version__ = "2.4.0"
__version__ = "3.8.2"

from .abc import BasePlayer, BaseClan
from .clans import RankedClan, Clan
from .client import Client
from .events import PlayerEvents, ClanEvents, WarEvents, EventsClient, ClientEvents
from .enums import (
PlayerHouseElementType,
Resource,
Role,
WarRound,
ACHIEVEMENT_ORDER,
BUILDER_TROOPS_ORDER,
HERO_ORDER,
PETS_ORDER,
ELIXIR_TROOP_ORDER,
DARK_ELIXIR_TROOP_ORDER,
HOME_TROOP_ORDER,
SIEGE_MACHINE_ORDER,
ELIXIR_SPELL_ORDER,
DARK_ELIXIR_SPELL_ORDER,
SPELL_ORDER,
SUPER_TROOP_ORDER,
UNRANKED_LEAGUE_DATA,
Expand All @@ -53,8 +58,7 @@
GatewayError,
PrivateWarLog,
)
from .login import login, login_with_keys
from .hero import Hero, Pet
from .hero import Equipment, Hero, Pet
from .http import BasicThrottler, BatchThrottler, HTTPClient
from .iterators import (
ClanIterator,
Expand All @@ -73,10 +77,11 @@
LegendStatistics,
LoadGameData,
Location,
PlayerHouseElement,
Timestamp,
TimeDelta,
Label,
WarLeague,
BaseLeague
)
from .players import Player, ClanMember, RankedPlayer
from .player_clan import PlayerClan
Expand Down
133 changes: 81 additions & 52 deletions coc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def __init__(self, data, townhall):

self._townhall = townhall

# copies for a static hash
self.__name = data['name']
self.__level = data['level']
self.__village = data['village']
self.__is_active = data.get("superTroopIsActive")

def __repr__(self):
attrs = [
("name", self.name),
Expand All @@ -180,20 +186,29 @@ def __repr__(self):
return "<%s %s>" % (
self.__class__.__name__, " ".join("%s=%r" % t for t in attrs),)

def __eq__(self, other):
return self.name == other.name and self.level == other.level \
and self.village == other.village and self.is_active == other.is_active

def __hash__(self):
return hash((self.__name, self.__level, self.__village, self.__is_active))


@classmethod
def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):
def _load_json_meta(cls, json_meta: dict, id, name: str, lab_to_townhall):
cls.id = int(id)
cls.name = name
cls.lab_to_townhall = lab_to_townhall

cls.range = try_enum(UnitStat, troop_meta.get("AttackRange"))
cls.dps = try_enum(UnitStat, troop_meta.get("DPS"))
cls.ground_target = _get_maybe_first(troop_meta, "GroundTargets",
default=True)
cls.hitpoints = try_enum(UnitStat, troop_meta.get("Hitpoints"))
levels_available = [key for key in json_meta.keys() if key.isnumeric()]

cls.ground_target = json_meta.get("GroundTargets", True)
cls.range = try_enum(UnitStat, [json_meta.get(level).get("AttackRange") for level in levels_available])
cls.dps = try_enum(UnitStat, [json_meta.get(level).get("DPS") for level in levels_available])
cls.hitpoints = try_enum(UnitStat, [json_meta.get(level).get("Hitpoints") for level in levels_available])

# get production building
production_building = troop_meta.get("ProductionBuilding", [None])[0]
production_building = json_meta.get("ProductionBuilding")
if production_building == "Barrack":
cls.is_elixir_troop = True
elif production_building == "Dark Elixir Barrack":
Expand All @@ -213,75 +228,79 @@ def _load_json_meta(cls, troop_meta, id, name, lab_to_townhall):

# without production_building, it is a hero
if not production_building:
laboratory_levels = troop_meta.get("LaboratoryLevel")
laboratory_levels = [json_meta.get(level).get("LaboratoryLevel") for level in levels_available]
else:
# it is a troop or spell or siege
prod_unit = buildings.get(production_building)
if production_building in ("SiegeWorkshop", "Spell Forge", "Mini Spell Factory",
"Dark Elixir Barrack", "Barrack", "Barrack2"):
min_prod_unit_level = troop_meta.get("BarrackLevel", [None, ])[0]
min_prod_unit_level = json_meta.get("BarrackLevel", None)
# there are some special troops, which have no BarrackLevel attribute
if not min_prod_unit_level:
laboratory_levels = troop_meta.get("LaboratoryLevel")
laboratory_levels = [json_meta.get(level).get("LaboratoryLevel") for level in levels_available]
else:
# get the min th level were we can unlock by the required level of the production building
min_th_level = [th for i, th in
enumerate(prod_unit["TownHallLevel"], start=1)
if i == min_prod_unit_level]
#get the townhall level of the spot where prod building level is equal to the one of the unit
min_th_level = prod_unit.get(str(min_prod_unit_level)).get("TownHallLevel", 0)
# map the min th level to a lab level
[first_lab_level] = [lab_level for lab_level, th_level in
lab_to_townhall.items()
if th_level in min_th_level]
[first_lab_level] = [lab_level for lab_level, th_level in lab_to_townhall.items() if th_level == min_th_level]
# the first_lab_level is the lowest possible (there are some inconsistencies with siege machines)
# To handle them properly, replacing all lab_level lower than first_lab_level with first_lab_level
laboratory_levels = []
for lab_level in troop_meta.get("LaboratoryLevel"):
for lab_level in [json_meta.get(level).get("LaboratoryLevel", 1) for level in levels_available]:
laboratory_levels.append(max(lab_level, first_lab_level))




elif production_building == "Pet Shop":
min_prod_unit_level = troop_meta.get("LaboratoryLevel", [None, ])[0]
# there are some special troops, which have no BarrackLevel attribute
min_prod_unit_level = json_meta.get("1").get("LaboratoryLevel")

# get the min th level were we can unlock by the required level of the production building
min_th_level = [th for i, th in
enumerate(prod_unit["TownHallLevel"], start=1)
if i == min_prod_unit_level]
min_th_level = prod_unit.get(str(min_prod_unit_level)).get("TownHallLevel", 0)

# map the min th level to a lab level
[first_lab_level] = [lab_level for lab_level, th_level in
lab_to_townhall.items()
if th_level in min_th_level]
[first_lab_level] = [lab_level for lab_level, th_level in lab_to_townhall.items() if th_level == min_th_level]
# the first_lab_level is the lowest possible (there are some inconsistencies with siege machines)
# To handle them properly, replacing all lab_level lower than first_lab_level with first_lab_level
laboratory_levels = []
for lab_level in troop_meta.get("LaboratoryLevel"):
for lab_level in [json_meta.get(level).get("LaboratoryLevel") for level in levels_available]:
laboratory_levels.append(max(lab_level, first_lab_level))

else:
return

cls.lab_level = try_enum(UnitStat, laboratory_levels)
cls.housing_space = _get_maybe_first(troop_meta, "HousingSpace", default=0)
cls.speed = try_enum(UnitStat, troop_meta.get("Speed"))
cls.housing_space = json_meta.get("HousingSpace", 0)

cls.speed = try_enum(UnitStat, [json_meta.get(level).get("Speed") for level in levels_available])
cls.level = cls.dps and UnitStat(range(1, len(cls.dps) + 1))

# all 3
cls.upgrade_cost = try_enum(UnitStat, troop_meta.get("UpgradeCost"))
cls.upgrade_resource = Resource(value=troop_meta["UpgradeResource"][0])
cls.upgrade_time = try_enum(UnitStat,
[TimeDelta(hours=hours) for hours in
troop_meta.get("UpgradeTimeH", [])])
cls._is_home_village = False if troop_meta.get("VillageType") else True
cls.upgrade_cost = try_enum(UnitStat, [json_meta.get(level).get("UpgradeCost") for level in levels_available])
cls.upgrade_resource = Resource(value=json_meta.get("UpgradeResource"))
upgrade_times = [
TimeDelta(hours=json_meta.get(level, {}).get("UpgradeTimeH"))
for level in levels_available
if json_meta.get(level, {}).get("UpgradeTimeH") is not None
]
cls.upgrade_time = try_enum(UnitStat, upgrade_times)

cls._is_home_village = False if json_meta.get("VillageType") else True
cls.village = "home" if cls._is_home_village else "builderBase"

# spells and troops
cls.training_cost = try_enum(UnitStat, troop_meta.get("TrainingCost"))
cls.training_time = try_enum(UnitStat, troop_meta.get("TrainingTime"))
cls.training_time = TimeDelta(seconds=json_meta.get("TrainingTime"))

# only heroes
cls.ability_time = try_enum(UnitStat, troop_meta.get("AbilityTime"))
cls.ability_troop_count = try_enum(UnitStat, troop_meta.get("AbilitySummonTroopCount"))
cls.required_th_level = try_enum(UnitStat, troop_meta.get("RequiredTownHallLevel") or laboratory_levels)
cls.regeneration_time = try_enum(
UnitStat, [TimeDelta(minutes=value) for value in troop_meta.get("RegenerationTimeMinutes", [])]
)
cls.ability_time = try_enum(UnitStat, [json_meta.get(level).get("AbilityTime") for level in levels_available])
cls.ability_troop_count = try_enum(UnitStat, [json_meta.get(level).get("AbilitySummonTroopCount") for level in levels_available])

required_townhall_levels = [json_meta.get(level).get("RequiredTownHallLevel") for level in levels_available]
cls.required_th_level = try_enum(UnitStat, required_townhall_levels if any(required_townhall_levels) else laboratory_levels)

regeneration_times = [
TimeDelta(minutes=json_meta.get(level, {}).get("RegenerationTimeMinutes"))
for level in levels_available
if json_meta.get(level, {}).get("RegenerationTimeMinutes") is not None
]
cls.regeneration_time = try_enum(UnitStat, regeneration_times)

cls.is_loaded = True
return cls
Expand Down Expand Up @@ -326,11 +345,13 @@ class DataContainerHolder:
def __init__(self):
self.loaded = False

def _load_json(self, object_ids, english_aliases, lab_to_townhall):
def _load_json(self, english_aliases, lab_to_townhall):
with open(self.FILE_PATH) as fp:
data = ujson.load(fp)

id = 2000
for c, [supercell_name, meta] in enumerate(data.items()):

# Not interested if it doesn't have a TID, since it likely isn't a real troop.
if not meta.get("TID"):
continue
Expand All @@ -340,8 +361,16 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
continue

# SC game files have "DisableProduction" true for all pet objects, which we want
if "DisableProduction" in meta and "pets" not in str(
self.FILE_PATH):
if meta.get("DisableProduction") and "pets" not in str(self.FILE_PATH):
continue

# ignore deprecated content
if meta.get("Deprecated"):
continue

#hacky but the aliases convert so that isnt great
IGNORED_PETS = ["Unused", "PhoenixEgg"]
if "pets" in str(self.FILE_PATH) and supercell_name in IGNORED_PETS:
continue

# A bit of a hacky way to create a "copy" of a new Troop object that hasn't been initiated yet.
Expand All @@ -350,11 +379,11 @@ def _load_json(self, object_ids, english_aliases, lab_to_townhall):
dict(self.data_object.__dict__))
new_item._load_json_meta(
meta,
id=object_ids.get(supercell_name, c),
name=english_aliases[meta["TID"][0]][0],
id=id,
name=english_aliases[meta.get("TID")],
lab_to_townhall=lab_to_townhall,
)

id += 1
self.items.append(new_item)
self.item_lookup[new_item.name] = new_item

Expand Down
Loading
Loading