Skip to content

Commit

Permalink
Fixed some get methods and added large_fetch_following.
Browse files Browse the repository at this point in the history
  • Loading branch information
FeralAmagai committed Jul 16, 2023
1 parent 5ad1e38 commit d9ca0b4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: pymino
Version: 1.2.3.3
Version: 1.2.3.4
Summary: Easily create a bot for Amino Apps using a modern easy to use synchronous library.
Home-page: https://github.com/forevercynical/pymino
Author: forevercynical
Expand Down
2 changes: 1 addition & 1 deletion pymino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__author__ = 'cynical'
__license__ = 'MIT'
__copyright__ = 'Copyright 2023 Cynical'
__version__ = '1.2.3.3'
__version__ = '1.2.3.4'
__description__ = 'A Python wrapper for the aminoapps.com API'

from .bot import Bot as Bot
Expand Down
37 changes: 35 additions & 2 deletions pymino/ext/async_global_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ async def fetch_followers(self, userId: str, start: int = 0, size: int = 25) ->
))


@authenticated
async def fetch_following(self, userId: str, start: int = 0, size: int = 25) -> UserProfileList:
"""
Fetches the user profiles of the users that the specified user is following.
Expand Down Expand Up @@ -838,8 +837,42 @@ async def fetch_following(self, userId: str, start: int = 0, size: int = 25) ->
url = f"/g/s/user-profile/{userId}/joined?start={start}&size={size}"
))

async def large_fetch_following(self, userId: str, size: int = 25, pageToken: str = None, ignoreMembership: bool = True) -> FollowerList:
"""
Fetches the user profiles of the users that the specified user is following.
:param userId: The ID of the user.
:type userId: str
:param size: The number of user profiles to fetch. (Default: 25)
:type size: int, optional
:param pageToken: The page token to fetch from. (Default: None)
:type pageToken: str, optional
:param ignoreMembership: Whether to ignore membership. (Default: True)
:type ignoreMembership: bool, optional
:return: A `FollowerList` object containing the user profiles.
:rtype: FollowerList
This function sends a GET request to the API to fetch the user profiles of the users that the specified user is following.
`FollowerList` represents a list of user profiles.
**Example usage:**
>>> following = client.large_fetch_following("user123")
... for userId in following.members.userId:
... print(userId)
"""
if pageToken:
return FollowerList(await self.make_request(
method = "GET",
url = f"/g/s/user-profile/{userId}/joined?size={size}&pageToken={pageToken}&pagingType=t&ignoreMembership={1 if ignoreMembership else 0}"
))

return FollowerList(await self.make_request(
method = "GET",
url = f"/g/s/user-profile/{userId}/joined?pagingType=t&size={size}&ignoreMembership={1 if ignoreMembership else 0}"
))


@authenticated
async def fetch_visitors(self, userId: str, start: int = 0, size: int = 25) -> UserProfileList:
"""
Fetches the visitors of a user profile.
Expand Down
28 changes: 27 additions & 1 deletion pymino/ext/entities/userprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,4 +1323,30 @@ def __init__(self, data: dict):
#self.extensions: list = [x.extensions for x in parser]
self.visit_privacy: list = [x.visit_privacy for x in parser]
self.stories_count: list = [x.stories_count for x in parser]
self.blogs_count: list = [x.blogs_count for x in parser]
self.blogs_count: list = [x.blogs_count for x in parser]

class Pagging:
def __init__(self, data: dict):
self._data = data.get("paging") if isinstance(data, dict) else data
self.prev_page_token = None
self.next_page_token = None

if isinstance(data, dict):
self.prev_page_token: Union[str, None] = self._data.get("prevPageToken")
self.next_page_token: Union[str, None] = self._data.get("nextPageToken")

def json(self) -> dict:
return self._data

class FollowerList:
def __init__(self, data: dict):
self._data = data
self.paging = None
self.members = None

if isinstance(data, dict):
self.paging = Pagging(self._data)
self.members = UserProfileList(self._data)

def json(self) -> dict:
return self._data
37 changes: 35 additions & 2 deletions pymino/ext/global_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,6 @@ def fetch_followers(self, userId: str, start: int = 0, size: int = 25) -> UserPr
))


@authenticated
def fetch_following(self, userId: str, start: int = 0, size: int = 25) -> UserProfileList:
"""
Fetches the user profiles of the users that the specified user is following.
Expand All @@ -914,13 +913,47 @@ def fetch_following(self, userId: str, start: int = 0, size: int = 25) -> UserPr
... for profile in following.userId:
... print(profile)
"""

return UserProfileList(self.make_request(
method = "GET",
url = f"/g/s/user-profile/{userId}/joined?start={start}&size={size}"
))

def large_fetch_following(self, userId: str, size: int = 25, pageToken: str = None, ignoreMembership: bool = True) -> FollowerList:
"""
Fetches the user profiles of the users that the specified user is following.
:param userId: The ID of the user.
:type userId: str
:param size: The number of user profiles to fetch. (Default: 25)
:type size: int, optional
:param pageToken: The page token to fetch from. (Default: None)
:type pageToken: str, optional
:param ignoreMembership: Whether to ignore membership. (Default: True)
:type ignoreMembership: bool, optional
:return: A `FollowerList` object containing the user profiles.
:rtype: FollowerList
This function sends a GET request to the API to fetch the user profiles of the users that the specified user is following.
`FollowerList` represents a list of user profiles.
**Example usage:**
>>> following = client.large_fetch_following("user123")
... for userId in following.members.userId:
... print(userId)
"""
if pageToken:
return FollowerList(self.make_request(
method = "GET",
url = f"/g/s/user-profile/{userId}/joined?size={size}&pageToken={pageToken}&pagingType=t&ignoreMembership={1 if ignoreMembership else 0}"
))

return FollowerList(self.make_request(
method = "GET",
url = f"/g/s/user-profile/{userId}/joined?pagingType=t&size={size}&ignoreMembership={1 if ignoreMembership else 0}"
))

@authenticated
def fetch_visitors(self, userId: str, start: int = 0, size: int = 25) -> UserProfileList:
"""
Fetches the visitors of a user profile.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pymino
version = 1.2.3.3
version = 1.2.3.4
author = forevercynical
author_email = me@cynical.gg
description = Easily create a bot for Amino Apps using a modern easy to use synchronous library.
Expand Down

0 comments on commit d9ca0b4

Please sign in to comment.