Skip to content

Commit

Permalink
Merge pull request #62 from LEv145:dev
Browse files Browse the repository at this point in the history
V 1.0
  • Loading branch information
LEv145 authored Nov 23, 2021
2 parents 634147e + 03ab463 commit 6b3b2c9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
venv
.*
__pycache__
test.py
dist
spore.py.egg-info
static_tests
.pyinstaller_*
venv*
pyinstaller_builds
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
MAKEDIR = pyinstaller_builds


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

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

.PHONY: clean
clean:
rm .pyinstaller_*
rm -R pyinstaller_builds
59 changes: 55 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,65 @@
# Spore REST API asyncio client
* Python 3.7+

# How to use
```
> spore_cli.exe --help
Usage: spore_cli [OPTIONS] COMMAND [ARGS]...
CLI for Spore REST API
Options:
--help Show this message and exit.
Commands:
get-asset-comments Get comments of the asset
get-asset-info Get asset information
get-creature Get creature
get-sporecast-assets Get assets of the sporecast
get-stats Get stats
get-user-achievements Get achievements of the user
get-user-assets Get creature of the user
get-user-buddies Get buddies of the user
get-user-info Get user information
get-user-sporecasts Get sporecasts of the user
get-user-subscribers Get subscribers of the user
search-assets Search assets
> spore_cli.exe search-assets --help
Usage: spore_cli search-assets [OPTIONS] {top_rated|top_rated_new|newest|featu
red|maxis_made|random|cute_and_creepy}
[START_INDEX] [LENGTH]
[[building|creature|vehicle|adventure|ufo]]
Search assets
Options:
--help Show this message and exit.
> spore_cli.exe get-creature 500267423060 # Get json info of creature
{"asset_id": 500267423060, "cost": 4065, "health": 3.0, "height": 1.3428643, "meanness": 9.0, "cuteness": 71.26385, "sense": 1.0, "bonecount": 44.0, "footcount": 4.0, "graspercount": 0.0, "basegear": 0.0, "carnivore": 1.0, "herbivore": 0.0, "glide": 0.0, "sprint": 2.0, "stealth": 2.0, "bite": 3.0, "charge": 2.0, "strike": 4.0, "spit": 0.0, "sing": 1.0, "dance": 2.0, "gesture": 5.0, "posture": 0.0}
```

# Build
## Linux
Build binary:
```
make binary
```

**Install:**
Build for python
```
make build
```

# Work in Python

## Install:
```py
pip install git+https://github.com/LEv145/spore.py
```


**Simple examples:**
## Simple examples
```py
import asyncio

Expand Down Expand Up @@ -46,7 +97,7 @@ def main() -> None:
main()
```

**Client methods:**
## Client methods

```py
get_stats() -> Stats
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
},
entry_points="""
[console_scripts]
spore=spore_api.scripts.spore_cli:cli
spore_cli=spore_api.__main__:cli
"""
)
28 changes: 14 additions & 14 deletions spore_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ async def cli():
"""CLI for Spore REST API"""


@cli.command()
@cli.command(help="Get stats")
async def get_stats():
async with _client as client:
result = await client.get_stats()
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get creature")
@click.argument("asset_id", type=int)
async def get_creature(asset_id: int):
async with _client as client:
Expand All @@ -32,7 +32,7 @@ async def get_creature(asset_id: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get user information")
@click.argument("username", type=str)
async def get_user_info(username: str):
async with _client as client:
Expand All @@ -42,7 +42,7 @@ async def get_user_info(username: str):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get creature of the user")
@click.argument("username", type=str)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -56,7 +56,7 @@ async def get_user_assets(username: str, start_index: int, length: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get sporecasts of the user")
@click.argument("username", type=str)
async def get_user_sporecasts(username: str):
async with _client as client:
Expand All @@ -66,7 +66,7 @@ async def get_user_sporecasts(username: str):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get achievements of the user")
@click.argument("username", type=str)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -80,7 +80,7 @@ async def get_user_achievements(username: str, start_index: int, length: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get buddies of the user")
@click.argument("username", type=str)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -94,7 +94,7 @@ async def get_user_buddies(username: str, start_index: int, length: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get subscribers of the user")
@click.argument("username", type=str)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -108,7 +108,7 @@ async def get_user_subscribers(username: str, start_index: int, length: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get asset information")
@click.argument("asset_id", type=int)
async def get_asset_info(asset_id: int):
async with _client as client:
Expand All @@ -118,7 +118,7 @@ async def get_asset_info(asset_id: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get comments of the asset")
@click.argument("asset_id", type=int)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -132,7 +132,7 @@ async def get_asset_comments(asset_id: int, start_index: int, length: int):
click.echo(result.to_json())


@cli.command()
@cli.command(help="Get assets of the sporecast")
@click.argument("sporecast_id", type=int)
@click.argument("start_index", type=int, default=1)
@click.argument("length", type=int, default=10)
Expand All @@ -146,7 +146,7 @@ async def get_sporecast_assets(sporecast_id: int, start_index: int, length: int)
click.echo(result.to_json())


@cli.command()
@cli.command(help="Search assets")
@click.argument(
"view_type",
type=click.Choice(ViewType._member_names_, case_sensitive=False)
Expand All @@ -158,9 +158,9 @@ async def get_sporecast_assets(sporecast_id: int, start_index: int, length: int)
type=click.Choice(AssetType._member_names_, case_sensitive=False),
required=False
)
async def assets_search(view_type: str, start_index: int, length: int, asset_type: Optional[str]):
async def search_assets(view_type: str, start_index: int, length: int, asset_type: Optional[str]):
async with _client as client:
result = await client.assets_search(
result = await client.search_assets(
view_type=ViewType[view_type],
start_index=start_index,
length=length,
Expand Down
2 changes: 1 addition & 1 deletion spore_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def get_user_subscribers(
)
)

async def assets_search(
async def search_assets(
self,
view_type: ViewType,
start_index: Union[int, str],
Expand Down

0 comments on commit 6b3b2c9

Please sign in to comment.