erkghlerngm44 / aniffinity Goto Github PK
View Code? Open in Web Editor NEWCalculate affinity between AniList, Kitsu and MyAnimeList users
Home Page: https://aniffinity.readthedocs.io
License: MIT License
Calculate affinity between AniList, Kitsu and MyAnimeList users
Home Page: https://aniffinity.readthedocs.io
License: MIT License
Current example:
"Shared rated anime count between
xxx
andhttps://myanimelist.net/profile/yyy
is less than eleven"
Exception messages that state a users' username (that isn't the "base user") should have the username resolved, with that being returned instead of whatever the user specified (in this case, a URL was specified). The users in the messages should ideally contain the "username" and "service", following something along the lines of: SERVICE:username
.
Ideal example:
"Shared rated anime count between
ANILIST:xxx
andMYANIMELIST:yyy
is less than eleven"
So the package can be restricted to use one service only, so the service
won't have to be specified on every request.
Currently it defaults to ANILIST
while showing a warning, if no service
is specified.
Maybe some examples:
import aniffinity
aniffinity.endpoints.DEFAULT_SERVICE = "MYANIMELIST"
aniffinity.Aniffinity("erkghlerngm44")
...
or possibly specified in the Aniffinity
class?
import aniffinity
af = aniffinity.Aniffinity("erkghlerngm44", base_service="ANILIST", ...something)
Or possibly something else?
When #13 goes ahead, it makes sense to allow the username/service to be specified in the above form.
Example:
>>> aniffinity.Aniffinity("ANILIST:erkghlerngm44")
# Aniffinity(base_user="erkghlerngm44", base_service="ANILIST", ...)
Might work by doing a check for a :
(or maybe a regex /(?P<service>\w+):(?P<user>[a-z0-9_-]+)/i
), splitting into respective values, and recursively passing back into .resolver.resolve_user
.
I modified the code from here:
import time
import aniffinity
time.sleep(2)
success = False
for i in range(5):
print(i)
try:
af = aniffinity.Aniffinity("purplepinapples", base_service="MyAnimeList")
affinity, shared = af.calculate_affinity("lanblade", service="MyAnimeList")
print(affinity, shared)
# Rate limit exceeded. Halt your script and try again
except aniffinity.exceptions.RateLimitExceededError:
time.sleep(10)
continue
# Any other aniffinity exception.
# Affinity can't be calculated for some reason.
# ``AniffinityException`` is the base exception class for
# all aniffinity exceptions
except aniffinity.exceptions.AniffinityException:
break
# Exceptions not covered by aniffinity. Not sure what
# you could do here. Feel free to handle however you like
except Exception as e:
print("Exception: `{}`".format(e))
break
# Success!
else:
success = True
break
The code above fails with a RateLimitExceededError
.
Even increasing the time.sleep
to over a minute does nothing, since in order to process purplepinapples
or lanblade
(which I chose because of their length), it takes around 50 load.json
requests, meaning its bound to exceed the API limit sometime in this loop.
I have a crude fix on my fork, for which the code above succeeds.
Perhaps accepting an argument in aniffinity.Affinity
and aniffinity.calculate_affinity
like wait_time
that waits between paginated requests?
10dp should be more than enough for most cases, with 2dp probably being the limit between "useful" and "unnecessary padding".
Values beyond 10dp are arguably "unnecessary padding", and have the greatest chance of introducing some form of floating-point error.
This can, of course, be overridden by the user by specifying False
for round
.
Re erkghlerngm44/malaffinity#1
It's possible ๐ฎ
Though I'm having to end up trudging through 68,000+ lines of JSON and pairing:
in order to get it to work, so it's not going to be fast...
Ah well, once the endpoint is written, adding it in shouldn't be an issue.
Things that may need changing in docs:
SERVICE:username
(#15) support to "Passing Arguments to the Class and its Methods" in Walkthrough page.for user in users:
and then indent everything else..models.User
and .models.Affinity
to API page.The current test suite is designed to work with MALAffinity.
May be worth deleting the suite for now, and re-adding it when the new one is up and running.
Something to add in, if it doesn't slow down the function substantially (over many runs).
Though there's not really much point? The code using it wouldn't need to be changed, and I'm not sure if the function would even be used outside of this package and the soulmate finder...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.