Skip to content

Commit 171ca8d

Browse files
committed
Merge branch 'rewrite' into master
# Conflicts: # coc/__init__.py # coc/clans.py # coc/client.py # coc/enums.py # coc/events.py # coc/login.py # coc/miscmodels.py # coc/players.py # docs/miscellaneous/changelog.rst # examples/events.py # examples/war_logs.py # setup.py
2 parents d3ad0c2 + 4529261 commit 171ca8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+9133
-3778
lines changed

.github/workflows/push-to-pypi.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
release:
3+
types: [created]
4+
5+
jobs:
6+
deploy:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: '3.x'
14+
- name: Install dependencies
15+
run: |
16+
python -m pip install --upgrade pip
17+
pip install setuptools wheel twine
18+
- name: Build and publish
19+
env:
20+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
21+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
22+
run: |
23+
python setup.py sdist bdist_wheel
24+
twine upload dist/*

.github/workflows/tests.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: coc.py Workflows
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
# You can use PyPy versions in python-version.
11+
# For example, pypy2 and pypy3
12+
matrix:
13+
python-version: [3.8]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
# You can test your matrix by printing the current Python version
22+
- name: Display Python version
23+
run: python -c "import sys; print(sys.version)"
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install discord.py==1.5.0
28+
pip install -r requirements.txt
29+
- name: Running examples as tests
30+
env:
31+
DEV_SITE_EMAIL: ${{ secrets.DEV_SITE_EMAIL }}
32+
DEV_SITE_PASSWORD: ${{ secrets.DEV_SITE_PASSWORD }}
33+
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
34+
LINKS_API_USERNAME: ${{ secrets.LINKS_API_USERNAME }}
35+
LINKS_API_PASSWORD: ${{ secrets.LINKS_API_PASSWORD }}
36+
RUNNING_TESTS: true
37+
run: |
38+
python -m examples.discord_bot
39+
python -m examples.discord_links
40+
python -m examples.events
41+
python -m examples.war_logs

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# creds
107+
examples/creds.py
108+
109+
# vscode
110+
.vscode/

.pre-commit-config.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.pylintrc

Lines changed: 0 additions & 21 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 mathsman5133
4-
3+
Copyright (c) 2019-2020 mathsman5133
54
Permission is hereby granted, free of charge, to any person obtaining a copy
65
of this software and associated documentation files (the "Software"), to deal
76
in the Software without restriction, including without limitation the rights

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
include README.rst
22
include LICENSE
3-
include requirements.txt
3+
include requirements.txt
4+
include coc/py.typed
5+
recursive-include coc *.pyi

README.rst

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ coc.py
1010
.. image:: https://img.shields.io/pypi/pyversions/discord.py.svg
1111
:target: https://pypi.python.org/pypi/coc.py
1212
:alt: PyPI supported Python versions
13-
.. image:: https://travis-ci.org/mathsman5133/coc.py.svg?branch=master
14-
:target: https://travis-ci.org/mathsman5133/coc.py
15-
:alt: Travis CI info
1613

1714

1815
Easy to use asynchronous Clash of Clans API wrapper in Python.
@@ -22,8 +19,7 @@ Key Features
2219
- Asynchronous code
2320
- Entire coverage of the official Clash of Clans API
2421
- Email/password login removes the stress of managing tokens
25-
- Optimised for speed and performance
26-
- Completely customisable cache
22+
- Optimised for speed, memory and performance
2723

2824
Getting Started
2925
================
@@ -55,36 +51,44 @@ This example will get a player with a certain tag, and search for 5 clans with a
5551
import asyncio
5652
5753
client = coc.login('email', 'password')
58-
loop = asyncio.get_event_loop()
5954
60-
player = loop.run_until_complete(client.get_player('tag'))
61-
print(player.name)
55+
async def main():
56+
player = await client.get_player("tag")
57+
print("{0.name} has {0.trophies} trophies!".format(player))
6258
63-
async def get_five_clans(name):
64-
players = await client.search_clans(name=name, limit=5)
65-
for n in players:
66-
print(n, n.tag)
59+
clans = await client.search_clans(name="Best Clan Ever", limit=5)
60+
for clan in clans:
61+
print("{0.name} ({0.tag}) has {0.member_count} members".format(clan))
6762
68-
if __name__ == '__main__':
69-
loop.run_until_complete(get_five_clans('name'))
70-
loop.run_until_complete(client.close())
63+
try:
64+
war = await client.get_current_war("#clantag")
65+
print(f"{0.clan_tag} is currently in {0.state} state.".format(war))
66+
except coc.PrivateWarLog:
67+
print("Uh oh, they have a private war log!")
68+
69+
client.loop.run_until_complete(main())
7170
7271
Basic Events Example
7372
---------------------
74-
This script will run forever, printing to the terminal whenever someone joins the clan.
73+
This script will run forever, printing to the terminal
74+
whenever someone joins the clan or a member of the clan donates troops.
7575

7676
.. code:: py
7777
7878
import coc
79-
import asyncio
8079
8180
client = coc.login('email', 'password', client=coc.EventsClient)
8281
8382
@client.event
84-
async def on_clan_member_join(player, clan):
85-
print('{0.name} ({0.tag}) just joined {1.name} ({1.tag})!'.format(player, clan))
83+
@coc.ClanEvents.member_join(tags=["#clantag", "#clantag2"])
84+
async def foo(player, clan):
85+
print("{0.name} ({0.tag}) just joined {1.name} ({1.tag})!".format(player, clan))
8686
87-
client.add_clan_update('tag')
87+
@client.event
88+
@coc.ClanEvents.member_donations(tags=["#clantag", "#clantag2"])
89+
async def bar(old_member, member):
90+
troops_donated = member.donations - old_member.donations
91+
print("{0} just donated {1} troops!".format(member.name, troops_donated))
8892
8993
client.run_forever()
9094
@@ -94,39 +98,19 @@ For more examples see the examples directory
9498
Contributing
9599
--------------
96100
Contributing is fantastic and much welcomed! If you have an issue, feel free to open an issue and start working on it.
97-
A few things to bear in mind:
98-
99-
Installing the dev requirements:
100-
101-
.. code:: sh
102101

103-
pip install -r dev-requirements.txt
104-
105-
This will install all the dev requirements, such as pylint, sphinx and pre-commit. These are handy!
106-
107-
**Setting up a git pre-commit hook**
108-
109-
Code quality is important - the repo has automatic linting and CI implemented.
110-
111-
In order to keep the git history
112-
clean, a pre-commit hook will automatically lint your code according to the repo's standard before you push.
113-
114-
You can install this pre-commit hook with:
102+
If you wish to run, setup or work on documentation, you will need to install ``sphinx`` and a few related dependencies.
103+
These can be installed with:
115104

116105
.. code:: sh
117106
118-
pre-commit install
119-
120-
In your local terminal. The ``pre-commit`` module should have already been installed
121-
if you installed the dev-requirements
107+
pip install .[docs]
122108
123-
You can run all linting that will be run in CI with:
109+
If you wish to run linting, pylint, black and flake8 have been setup and can be run with:
124110

125111
.. code:: sh
126112
127113
python setup.py lint
128-
// or
129-
pre-commit run --all-files
130114
131115
Links
132116
------
@@ -136,9 +120,9 @@ Links
136120

137121
Disclaimer
138122
-----------
139-
- This content is not affiliated with, endorsed, sponsored, or specifically
140-
approved by Supercell and Supercell is not responsible for it.
141-
For more information see `Supercell's Fan Content Policy: <https://www.supercell.com/fan-content-policy.>`_
123+
This content is not affiliated with, endorsed, sponsored, or specifically
124+
approved by Supercell and Supercell is not responsible for it.
125+
For more information see `Supercell's Fan Content Policy. <https://www.supercell.com/fan-content-policy.>`_
142126

143127

144128

coc/__init__.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
"""
2-
Clash of Clans API Wrapper
3-
~~~~~~~~~~~~~~~~~~~
2+
MIT License
43
5-
A basic wrapper for the Clash of Clans API.
4+
Copyright (c) 2019-2020 mathsman5133
65
7-
:copyright: (c) 2015-2019 mathsman5133
8-
:license: MIT, see LICENSE for more details.
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
912
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
1023
"""
11-
__version__ = "0.3.4"
1224

13-
from .cache import Cache, CacheConfig, DefaultCache, MaxSizeCache, TimeToLiveCache
25+
__version__ = "1.0.0"
1426

15-
from .clans import Clan, SearchClan, BasicClan, WarClan, LeagueClan
27+
from .abc import BasePlayer, BaseClan
28+
from .clans import RankedClan, Clan
1629
from .client import Client
17-
from .events import EventsClient
30+
from .events import PlayerEvents, ClanEvents, WarEvents, EventsClient, ClientEvents
1831
from .enums import (
19-
CacheType,
2032
Role,
33+
WarRound,
2134
ACHIEVEMENT_ORDER,
2235
BUILDER_TROOPS_ORDER,
2336
DARK_ELIXIR_SPELL_ORDER,
@@ -42,7 +55,7 @@
4255
PrivateWarLog,
4356
)
4457
from .login import login
45-
from .http import HTTPClient
58+
from .http import BasicThrottler, BatchThrottler, HTTPClient
4659
from .iterators import (
4760
ClanIterator,
4861
PlayerIterator,
@@ -53,8 +66,8 @@
5366
from .miscmodels import (
5467
Achievement,
5568
Badge,
56-
EqualityComparable,
5769
Hero,
70+
Icon,
5871
League,
5972
LegendStatistics,
6073
Location,
@@ -64,21 +77,10 @@
6477
Label,
6578
WarLeague,
6679
)
67-
from .players import (
68-
Player,
69-
BasicPlayer,
70-
SearchPlayer,
71-
LeaguePlayer,
72-
LeagueRankedPlayer,
73-
WarMember,
74-
)
75-
from .wars import (
76-
BaseWar,
77-
WarLog,
78-
ClanWar,
79-
WarAttack,
80-
LeagueGroup,
81-
LeagueWar,
82-
LeagueWarLogEntry,
83-
)
80+
from .players import Player, ClanMember, RankedPlayer
81+
from .player_clan import PlayerClan
82+
from .war_clans import WarClan, ClanWarLeagueClan
83+
from .war_attack import WarAttack
84+
from .war_members import ClanWarLeagueClanMember, ClanWarMember
85+
from .wars import ClanWar, ClanWarLogEntry, ClanWarLeagueGroup
8486
from . import utils

0 commit comments

Comments
 (0)