Added User Class for getting user info (No modifying or auth requests)
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.
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).
Perfect, take your time, i'm just happy to help.
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
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.
It's all good. I'll get back to it when I have time.