API¶
-
class
aniffinity.
Aniffinity
(base_user=None, base_service=None, round=10, **kws)¶ The Aniffinity class.
The purpose of this class is to store a “base user“‘s scores, so affinity with other users can be calculated easily.
For the username
Josh
on the serviceAniList
, the class can be initialised as follows:from aniffinity import Aniffinity af = Aniffinity("Josh", base_service="AniList")
There are multiple ways of specifying this information, and multiple ways to initialise this class. For more info, read the documentation.
The instance, stored in
af
, will now holdJosh
’s scores.comparison()
andcalculate_affinity()
can now be called, to perform operations on this data.-
__init__
(base_user=None, base_service=None, round=10, **kws)¶ Initialise an instance of
Aniffinity
.The information required to retrieve a users’ score from a service are their “username” and “service”. For a list of “service”s, read the documentation.
Note
As this applies to the “base” user, the params used are
base_user
andbase_service
respectively.There are multiple ways of specifying the above information, and multiple aliases for services that can be used as shorthand. As docstrings are annoying to write, please refer to the documentation for a list of these. For an example of the simplest method to use, refer to the docstring for the
Aniffinity
class.Note
To avoid dealing with dodgy globals, this class MAY be initialised without the
base_user
argument, in the global scope (if you wish), butinit()
MUST be called sometime afterwards, with abase_user
andbase_service
passed, before affinity calculations take place.Example (for the username
Josh
on the serviceAniList
):from aniffinity import Aniffinity af = Aniffinity() ma.init("Josh", base_service="AniList")
The class should then be good to go.
Parameters: - base_user (str or tuple) – Base user
- base_service (str or None) – The service to use. If no value is specified
for this param, specify the service in the
base_user
param, either as part of a url, or in a tuple - round (int or False) – Decimal places to round affinity values to.
Specify
False
for no rounding - wait_time (int) – Wait time in seconds between paginated requests (default: 2)
-
calculate_affinity
(user, service=None)¶ Get the affinity between the “base user” and
user
.Note
The data returned will be a namedtuple, with the affinity and shared rated anime. This can easily be separated as follows:
affinity, shared = af.calculate_affinity(...)
Alternatively, the following also works:
affinity = af.calculate_affinity(...)
with the affinity and shared available as
affinity.value
andaffinity.shared
respectively.Note
The final affinity value may or may not be rounded, depending on the value of
_round
, set at class initialisation.Parameters: - user (str or tuple) – The user to calculate affinity with.
- service (str or None) – The service to use. If no value is specified
for this param, specify the service in the
user
param, either as part of a url, or in a tuple
Returns: (float affinity, int shared)
Return type: tuple
-
comparison
(user, service=None)¶ Get a comparison of scores between the “base user” and
user
.A Key-Value returned will consist of the following:
{ "ANIME_ID": [BASE_USER_SCORE, OTHER_USER_SCORE], ... }
Example:
{ "30831": [3, 8], "31240": [4, 7], "32901": [1, 5], ... }
Note
The
ANIME_ID
s will be the MyAnimeList anime ids. As annoying as it is, cross-compatibility is needed between services to get this module to work, and MAL ids are the best ones to use as other APIs are able to specify it. If you wish to use the anime ids for the service you specified, set the param<TO BE IMPLEMENTED>
to<TO BE IMPLEMENTED>
.Parameters: - user (str or tuple) – The user to compare the base users’ scores to.
- service (str or None) – The service to use. If no value is specified
for this param, specify the service in the
user
param, either as part of a url, or in a tuple
Returns: Mapping of
id
toscore
as described aboveReturn type: dict
-
init
(base_user, base_service=None)¶ Retrieve a “base user“‘s list, and store it in
_base_scores
.Parameters: - base_user (str or tuple) – Base user
- base_service (str or None) – The service to use. If no value is specified
for this param, specify the service in the
base_user
param, either as part of a url, or in a tuple
-