Skip to content

Commit

Permalink
Merge pull request #28 from LEv145:dev
Browse files Browse the repository at this point in the history
V0.4
  • Loading branch information
LEv145 authored Dec 13, 2021
2 parents 1ce448e + b8474b4 commit 214c2ca
Show file tree
Hide file tree
Showing 34 changed files with 1,002 additions and 302 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ exclude_lines =
if __name__ == .__main__.:
pragma: no cover
if TYPE_CHECKING:
...
pass
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 99
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: lev145
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
25 changes: 25 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Python package

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, 3.10]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
17 changes: 13 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

Dockerfile


# Releases
releases

# Pyinstaller
pyinstaller_builds

# VSCode files
.vscode/

Expand Down Expand Up @@ -41,7 +51,6 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
Expand Down Expand Up @@ -114,9 +123,9 @@ celerybeat.pid
# Environments
.env
.venv
env/
venv/
ENV/
*env*/
*venv*/
*ENV*/
env.bak/
venv.bak/

Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@

.PHONY: build
build:
pip install --editable .


.PHONY: binary
binary:
pyinstaller pyinstaller.spec --distpath pyinstaller_builds/linux_dist --workpath pyinstaller_builds/linux_build


.PHONY: mkinit
mkinit:
mkinit sporepedia -w --black --nomods --relative --recursive


.PHONY: run_tests
run_tests:
tox


.PHONY: coverage_status
coverage_status:
coverage run -m unittest discover tests "test_*"
coverage report -m


.PHONY: clear
clear:
rm -R build/ dist/ .eggs/ pyinstaller_builds/

141 changes: 141 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
# sporepedia.py
Unofficial API client for sporepedia (https://www.spore.com/sporepedia)


# How to use
```
> sporepedia --help
Usage: sporepedia [OPTIONS] COMMAND [ARGS]...
CLI for sporepedia
Options:
--help Show this message and exit.
Commands:
search Search from sporepedia
> sporepedia.exe search CAT --functions "is_civ_creature, is_adventure_creature, is_industry" --models "is_water" -F "most_popular_new"
{"result_size": 363, "results": [...]}
```
A simple and intuitive script, convenient output data in the form of json:3
(You can use a script from any programming language)

# Build

Build binary:
```
pyinstaller pyinstaller.spec \
--distpath pyinstaller_builds/dist \
--workpath pyinstaller_builds/build
```
Build for python (requires Python 3.7+)
```
pip install --editable .
```

# Work in Python
### Install:
```
pip install git+https://github.com/LEv145/sporepedia.py
```

Client:
```py
import asyncio

from sporepedia import (
SporepediaClient,
SearchParams,
FieldsSearchParam,
FunctionsSearchParam,
PurposesSearchParam,
SearchFilter,
)


async def main() -> None:
async with SporepediaClient() as client:
result = await client.search(
text="test",
lenght=20,
params=SearchParams(
fields=FieldsSearchParam(
is_name=True,
is_author=True,
is_tag=True,
),
functions=FunctionsSearchParam(
is_tribe_creature=True,
is_adventure_creature=True,
is_industry=True,
is_adv_collect=True,
is_adv_puzzle=True,
is_adv_template=True
),
purposes=PurposesSearchParam(
is_military=True,
is_cultural=True,
),
),
filter=SearchFilter.featured,
)
print(result) # SearchServiceResult(result_size=48, results=[...])


asyncio.run(main())
```
Low level API (More options to customize!>3):
```py
import asyncio

from sporepedia import (
APIClient,
)


async def main() -> None:
async with APIClient() as client:
result = await client.search(
text="test",
adv=1,
batch_id=2,
)
print(result) # SearchServiceResult(result_size=48, results=[...])


asyncio.run(main())
```


# Coverage
```
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------------------------------------------------
sporepedia/__init__.py 0 0 0 0 100%
sporepedia/__main__.py 0 0 0 0 100%
sporepedia/api/__init__.py 0 0 0 0 100%
sporepedia/api/client.py 0 0 0 0 100%
sporepedia/api/methods/__init__.py 0 0 0 0 100%
sporepedia/api/methods/dwr_parser.py 0 0 0 0 100%
sporepedia/api/methods/mixin_protocol.py 0 0 0 0 100%
sporepedia/api/methods/mixins/__init__.py 0 0 0 0 100%
sporepedia/api/methods/mixins/search/__init__.py 0 0 0 0 100%
sporepedia/api/methods/mixins/search/builders.py 0 0 0 0 100%
sporepedia/api/methods/mixins/search/composers.py 0 0 0 0 100%
sporepedia/api/methods/mixins/search/methods.py 0 0 0 0 100%
sporepedia/api/methods/mixins/search/models.py 0 0 0 0 100%
sporepedia/client.py 0 0 0 0 100%
tests/test_api.py 0 0 0 0 100%
tests/test_cli.py 0 0 0 0 100%
tests/test_client.py 0 0 0 0 100%
tests/test_dwr_parser.py 0 0 0 0 100%
tests/test_search.py 0 0 0 0 100%
-----------------------------------------------------------------------------------------------
TOTAL 0 0 0 0 100%
```

TODO:
- [ ] Autotest from git (Tox)
- [x] 100% tests
- [x] Cli client
- [ ] Docs
- [ ] New methods
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mypy]
ignore_missing_imports = True
strict_optional = True
implicit_reexport = True
warn_unused_ignores = False
disallow_any_generics = False
Loading

0 comments on commit 214c2ca

Please sign in to comment.