Skip to content

Commit

Permalink
Added option for loading older posts
Browse files Browse the repository at this point in the history
  • Loading branch information
MujyKun committed Jun 27, 2021
1 parent bd5b4fd commit ff416c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### What is it?
Weverse creates internal cache for the communities a user follows on [weverse.io](https://www.weverse.io/).
This is a **wrapper** for Weverse's private API, but will be referred to as an API on this repository.

### **[API Documentation](https://weverse.readthedocs.io/en/latest/)**

Expand Down Expand Up @@ -70,6 +71,8 @@ except InvalidToken:
print("Invalid Token")

# After calling the start method, you now have all the objects you would want to modify.
# The start method takes in parameters that can disable old posts from loading up
# if only the newer posts are wanted. More info on the documentation.

```

Expand Down
25 changes: 19 additions & 6 deletions Weverse/weverseasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,46 @@ class WeverseClientAsync(WeverseClient):
loop:
Asyncio Event Loop
Attributes are the same as :ref:`WeverseClient`.
"""

def __init__(self, loop=get_event_loop(), **kwargs):
self.loop = loop
super().__init__(**kwargs)

async def start(self):
async def start(self, create_old_posts=True, create_notifications=True):
"""Creates internal cache.
This is the main process that should be run.
This is a coroutine and must be awaited.
:parameter create_old_posts: (:class:`bool`) Whether to create cache for old posts.
:parameter create_notifications: (:class:`bool`) Whether to create/update cache for old notifications.
:raises: :class:`Weverse.error.PageNotFound`
:raises: :class:`Weverse.error.InvalidToken`
:raises: :class:`Weverse.error.BeingRateLimited`
"""
try:
if not self.web_session:
self.web_session = aiohttp.ClientSession()
await self.create_communities()

# create all communities that are subscribed to
await self.create_communities() # communities should be created no matter what

# create and update community artists and their tabs
await self.create_community_artists_and_tabs()
await self.get_user_notifications()
for community in self.all_communities.values():
await self.create_posts(community)

# create and update user notifications
if create_notifications:
await self.get_user_notifications()

# load up posts
if create_old_posts:
for community in self.all_communities.values():
await self.create_posts(community)

self.cache_loaded = True
except Exception as err:
raise err
Expand Down
25 changes: 20 additions & 5 deletions Weverse/weversesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,38 @@ class WeverseClientSync(WeverseClient):
def __init__(self, **kwargs):
super().__init__(**kwargs)

def start(self):
def start(self, create_old_posts=True, create_notifications=True):
"""Creates internal cache.
This is the main process that should be run.
:parameter create_old_posts: (:class:`bool`) Whether to create cache for old posts.
:parameter create_notifications: (:class:`bool`) Whether to create/update cache for old notifications.
:raises: :class:`Weverse.error.PageNotFound`
:raises: :class:`Weverse.error.InvalidToken`
:raises: :class:`Weverse.error.BeingRateLimited`
"""
try:
if not self.web_session:
self.web_session = requests.Session()
self.create_communities()

# create all communities that are subscribed to
self.create_communities() # communities should be created no matter what

# create and update community artists and their tabs
self.create_community_artists_and_tabs()
self.get_user_notifications()
for community in self.all_communities.values():
self.create_posts(community)

# create and update user notifications
if create_notifications:
self.get_user_notifications()

# load up posts
if create_old_posts:
for community in self.all_communities.values():
self.create_posts(community)

self.cache_loaded = True
except Exception as err:
raise err
Expand Down

0 comments on commit ff416c9

Please sign in to comment.