Skip to content

Commit

Permalink
Added korean triggers if an account is defaulted to korean
Browse files Browse the repository at this point in the history
  • Loading branch information
MujyKun committed Jul 18, 2021
1 parent 9662c1f commit 7650db0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ For example, you may see (This is just an example):
Then ``ABCDEFGHIJKLMNOPQRSTUVWXYZ`` would be your auth token for Weverse.
It is suggested to have the auth token as an environment variable.

IMPORTANT NOTE: Not all korean key-phrases may be kept track of. Scroll to the bottom of the Weverse page
when you are logged in and click "English" to set the account language to English.

#### CODE EXAMPLES

Expand Down
2 changes: 1 addition & 1 deletion Weverse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
__title__ = 'Weverse'
__author__ = 'MujyKun'
__license__ = 'MIT'
__version__ = '1.0.3'
__version__ = '1.0.4'
41 changes: 27 additions & 14 deletions Weverse/weverseclient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Union

from . import create_artist_objects, create_tab_objects, InvalidToken
from .models import Artist as w_Artist, \
Expand Down Expand Up @@ -240,27 +240,40 @@ def get_media_by_id(self, media_id) -> Optional[w_Media]:
return self.all_media.get(media_id)

@staticmethod
def determine_notification_type(notification_body) -> str:
def determine_notification_type(notification: Union[w_Notification, str]) -> str:
"""
Determine the post type based on the notification body.
Determine the post type based on the notification body or the Notification object itself.
Since notifications do not differentiate between Posts and Comments, this is for that purpose.
:param notification_body: The body of the notification.
:param notification: The message body of the notification or the notification itself.
:returns: A string with either
"comment", "media", "post", or "announcement".
"""
if isinstance(notification, w_Notification):
notification_body = notification.message
else:
notification_body = notification

comment_body_triggers = ["commented on", "replied to", "포스트에 댓글을 작성했습니다", "답글을 작성했습니다."]
post_body_triggers = ["님이 포스트를 작성했습니다", "created a new post!", "shared a moment with you",
"모먼트가 도착했습니다"]
media_triggers = ["Check out the new media", "새로운 미디어"]

announcement_body_triggers = ["New announcement", "NOTICE:", "(광고)", "(AD)"]

if "commented on" in notification_body or "replied to" in notification_body:
return "comment"
# if "shared a moment with you" in notification_body:
# return "tofans"
if "created a new post!" in notification_body or "shared a moment with you" in notification_body:
return "post"
if "Check out the new media" in notification_body:
return "media"
if "New announcement" in notification_body:
return "announcement"
for trigger in comment_body_triggers:
if trigger in notification_body:
return "comment"

for trigger in post_body_triggers:
if trigger in notification_body:
return "post"

for trigger in media_triggers:
if trigger in notification_body:
return "media"

for trigger in announcement_body_triggers:
if trigger in notification_body:
return "announcement"
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ Then ``ABCDEFGHIJKLMNOPQRSTUVWXYZ`` would be your auth token for Weverse.

It is suggested to have the auth token as an environment variable.

IMPORTANT NOTE: Not all korean key-phrases may be logged. Scroll to the bottom of the Weverse page when you are logged in
and click "English" to set the account language to English.


Asynchronous Usage
==================
Expand Down

0 comments on commit 7650db0

Please sign in to comment.