Skip to content

Commit

Permalink
Large refactoring to simplify code and remove duplicate code (#13)
Browse files Browse the repository at this point in the history
* Change imports in __init__ to be relative

* Move mutable arguments out of definition

* Reformat all types to derive from one of two base classes

* Add basic guide and example to readme

* Move data organization code to client_process.py to avoid repeated code

Also fix incorrect typehinting in the return values of many functions

* Fix bad ID in tests

* Move repeated API queries into a single "api_query()" function

Also, rewrite the httpx client opening to use a context window so it'll automatically close after the action

These changes also prompted the changing of many of the functions to static methods

* Change the "pass" for the bare exception catch to "raise" so exceptions are properly raised

* Error in README.md

* Update CHANGELOG.md

* Expand example in README.md

* Undo mistaken removal of dash

This commit reverts pyproject.toml to the original state

* Bump version to 1.1.0

From 1.0.9

---------

Co-authored-by: Ryan H <[email protected]>
  • Loading branch information
r-hensley and r-hensley authored Sep 3, 2024
1 parent a21b26b commit 9ca961d
Show file tree
Hide file tree
Showing 27 changed files with 1,141 additions and 2,516 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 1.1.0 (July 23rd, 2023)

Large refactoring to remove duplicate code.

### Changed

- Rebase all classes to be subclasses of a main "Object" class, or "Hashable" if the class has an id. This was to avoid the repetitive __repr__, __str__, and raw() definitions in every class, as well as allow things like implementation of __eq__ to all classes by writing it in only one place. ([commit](https://github.com/r-hensley/python-anilist/commit/15d57c753c7b5eb6624bdbfb719f82fc68f743db))
- Add some basic info to the readme, as well as an example.
- Consolidate duplicated code between the synhronous and asynchronous files into one "client_process.py" file ([commit](https://github.com/r-hensley/python-anilist/commit/a568ac77883ee2225287df849a59dea7cd658253))
- The IDs being used for one of the tests in the test file were no longer found on the tested user's profile, so they have been updated to a new ID for the sake of a successful test ([commit](https://github.com/r-hensley/python-anilist/commit/b0825364e22d2ad3ee9f18e2cb1f302081e52e00))
- Consolidate API calls into a single "api_query()" function ([commit](https://github.com/r-hensley/python-anilist/commit/4066a5371a1573ab6e28e1ab5d6901af678ba184))
- Changed all the "try ... except ... pass" blocks to "try ... except ... raise" to ensure proper propagation of errors. If a user wishes to ignore all errors they should do that in their program rather than the library suppressing all errors with no logs ([commit](https://github.com/r-hensley/python-anilist/commit/cba69086587ac164d5fc55eddccc58f9e5680b7b))

## 1.0.9 (February 16th, 2022)

### Added
Expand Down
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,50 @@ For the latest development version:
python3 -m pip install git+https://github.com/AmanoTeam/python-anilist.git#egg=python-anilist
```

## Basic starting guide

First, import the module
```py
import anilist
```

Next, define the client to interact with the API

```py
client = anilist.Client()
```

You can search for the name of something on the site using:
- `client.search_user(name, limit=10)`
- `client.search_anime(name, limit=10)`
- `client.search_manga(name, limit=10)`
- `client.search_character(name, limit=10)`
- `client.search_staff(name, limit=10)`

If you know the ID of something, then use the get() commands instead:
- `client.get_user(ID)`
- `client.get_anime(ID)`
etc.

Example code usage:

```py
import anilist

client = anilist.Client()

# a search returns a tuple (A, B) with A being the main data of the search,
# and B being a PageInfo object containing info about the page of the search result
search_result: tuple[list, PageInfo] = client.search_anime("madoka", limit=10)

madoka_list: list[Anime] = search_result[0] # taking "A" from the above tuple, this is a list of "Anime" objects

madoka_magica: Anime = madoka_list[0] # this chooses the first anime in the list of search results

print(madoka.title, madoka.id) # print that anime's title and anilist.co ID

>>> {'romaji': 'Mahou Shoujo Madoka☆Magica', 'english': 'Puella Magi Madoka Magica', 'native': '魔法少女まどか☆マギカ'} 9756
```
## What's left to do?

- Write the API Documentation.
Expand All @@ -44,7 +88,7 @@ python3 -m pip install git+https://github.com/AmanoTeam/python-anilist.git#egg=p

## License

Copyright © 2021-2022 [AmanoTeam](https://github.com/AmanoTeam)
Copyright © 2021-2023 [AmanoTeam](https://github.com/AmanoTeam)
and the python-anilist contributors

Licensed under the [Expat/MIT license](LICENSE).
Expand Down
Loading

0 comments on commit 9ca961d

Please sign in to comment.