Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added User Class for getting user info (No modifying or auth requests) #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mbgv
Copy link
Contributor

@mbgv mbgv commented Mar 16, 2022

Been working on this for a few months, postponing it, but I think that it is now ready. I did a lot of testing with big accounts and everything seems to work as intended. The code is a bit crammed and I didn't add comments or an example in the README. I can add comments later if it's necessary.
It accommodates all the info in Lists and Dicts, and also parses dates to datetime objects. Maybe the date parsing code can be moved to the Base class, so it can be used in other parts of the api. Still, it is a static method, so it can be executed just by importing the User class.
In my testing, there wasn't a need for any artificial delay. I didn't get banned even after 610 pages (Tested with an account that has over 61000 friends).
If anything else is needed from my part feel free to let me know.

mbgv and others added 4 commits January 7, 2022 05:44
Added a simple exception raiser that triggers when MyAnimeList temporarily blocks incoming requests when you exceed the bandwith limit.
Added User Class to get all the user info from a specific user by username. The code is a bit crammed but works well.
@darenliang
Copy link
Owner

Hi mblastergamer,

Thanks for taking the time to do this.

Adding User info is a great idea and I'm ok moving forward on this.

I'm quite busy lately, but I will review the code soon and see what else is needed (e.g. tests, documentation, and/or restructuring).

@mbgv
Copy link
Contributor Author

mbgv commented Mar 16, 2022

Perfect, take your time, i'm just happy to help.

@darenliang
Copy link
Owner

darenliang commented Mar 18, 2022

Currently looking at the code.

Just one thing I would like to ask. Do you think we should use CSS selectors instead?
The old code base relies on some large chains of bs4 calls, but it can be easily simplified via CSS selectors. This could be a good test to see if it's worth translating the rest of the codebase.

Example:

user_image = self._page.find("div", {"class": "user-image"}).findChildren("img")
self._image_url = None if user_image == [] else user_image[0]["data-src"]

is equivalent to

user_image = self._page.select_one(".user-image > img")
self._image_url = user_image["data-src"] if user_image else None

Reference:
https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors

I'm experimenting on this branch:
https://github.com/darenliang/mal-api/blob/pr-21-darenliang/mal/_user.py

@mbgv
Copy link
Contributor Author

mbgv commented Mar 23, 2022

Sorry for the late response, I have been quite busy. Yes, I didn't think about that when I was making the original code and some lines are quite long when they can be easily shortened by using css selectors. This error comes from my bad practice of coding bs4 calls piece by piece trying to reach some element.
Edit:
I was just looking at the branch and you did a great job shortening my mess, if you need my help with changing some of the code, tell me.

@darenliang
Copy link
Owner

It's all good. I'll get back to it when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants