mirror of https://gitlab.com/bashrc2/epicyon
Separate module for actor status
parent
62c8056224
commit
4e6bd76ccf
|
@ -12,8 +12,8 @@ import json
|
||||||
from roles import get_actor_roles_list
|
from roles import get_actor_roles_list
|
||||||
from skills import no_of_actor_skills
|
from skills import no_of_actor_skills
|
||||||
from skills import get_skills_from_list
|
from skills import get_skills_from_list
|
||||||
from utils import get_actor_status
|
from status import get_actor_status
|
||||||
from utils import actor_status_expired
|
from status import actor_status_expired
|
||||||
from utils import get_nickname_from_actor
|
from utils import get_nickname_from_actor
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
from utils import get_json_content_from_accept
|
from utils import get_json_content_from_accept
|
||||||
|
|
|
@ -26,8 +26,8 @@ from blocking import is_blocked_nickname
|
||||||
from blocking import is_blocked_domain
|
from blocking import is_blocked_domain
|
||||||
from content import valid_url_lengths
|
from content import valid_url_lengths
|
||||||
from posts import add_to_field
|
from posts import add_to_field
|
||||||
from utils import actor_status_expired
|
from status import actor_status_expired
|
||||||
from utils import get_actor_status
|
from status import get_actor_status
|
||||||
from utils import detect_mitm
|
from utils import detect_mitm
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
from utils import load_json
|
from utils import load_json
|
||||||
|
|
|
@ -11,7 +11,7 @@ import os
|
||||||
import time
|
import time
|
||||||
from flags import is_recent_post
|
from flags import is_recent_post
|
||||||
from flags import is_quote_toot
|
from flags import is_quote_toot
|
||||||
from utils import actor_status_expired
|
from status import actor_status_expired
|
||||||
from utils import get_quote_toot_url
|
from utils import get_quote_toot_url
|
||||||
from utils import get_actor_from_post_id
|
from utils import get_actor_from_post_id
|
||||||
from utils import contains_invalid_actor_url_chars
|
from utils import contains_invalid_actor_url_chars
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
__filename__ = "status.py"
|
||||||
|
__author__ = "Bob Mottram"
|
||||||
|
__license__ = "AGPL3+"
|
||||||
|
__version__ = "1.6.0"
|
||||||
|
__maintainer__ = "Bob Mottram"
|
||||||
|
__email__ = "bob@libreserver.org"
|
||||||
|
__status__ = "Production"
|
||||||
|
__module_group__ = "Core"
|
||||||
|
__accounts_data_path__ = None
|
||||||
|
__accounts_data_path_tests__ = False
|
||||||
|
|
||||||
|
from utils import date_utcnow
|
||||||
|
from utils import date_from_string_format
|
||||||
|
from utils import remove_html
|
||||||
|
from utils import standardize_text
|
||||||
|
|
||||||
|
MAX_STATUS_LENGTH = 100
|
||||||
|
|
||||||
|
|
||||||
|
def get_actor_status(profile_json: {}) -> str:
|
||||||
|
"""returns the actor status if it exists
|
||||||
|
https://codeberg.org/fediverse/fep/src/branch/main/fep/82f6/fep-82f6.md
|
||||||
|
"""
|
||||||
|
if not profile_json.get('sm:status'):
|
||||||
|
return ''
|
||||||
|
status = ''
|
||||||
|
if isinstance(profile_json['sm:status'], str):
|
||||||
|
status = profile_json['sm:status']
|
||||||
|
elif isinstance(profile_json['sm:status'], dict):
|
||||||
|
if profile_json['sm:status'].get('content'):
|
||||||
|
possible_status = profile_json['sm:status']['content']
|
||||||
|
if isinstance(status, str):
|
||||||
|
status = possible_status
|
||||||
|
if status:
|
||||||
|
status = remove_html(status)
|
||||||
|
if len(status) > MAX_STATUS_LENGTH:
|
||||||
|
status = status[:MAX_STATUS_LENGTH]
|
||||||
|
status = standardize_text(status)
|
||||||
|
return status
|
||||||
|
|
||||||
|
|
||||||
|
def actor_status_expired(actor_status_json: {}) -> bool:
|
||||||
|
"""Has the given actor status expired?
|
||||||
|
"""
|
||||||
|
if not actor_status_json.get('endTime'):
|
||||||
|
return False
|
||||||
|
if not isinstance(actor_status_json['endTime'], str):
|
||||||
|
return False
|
||||||
|
if 'T' not in actor_status_json['endTime'] or \
|
||||||
|
':' not in actor_status_json['endTime']:
|
||||||
|
return False
|
||||||
|
date_formats = (
|
||||||
|
"%Y-%m-%dT%H:%M:%S%z",
|
||||||
|
"%Y-%m-%dT%H:%M:%S%Z"
|
||||||
|
)
|
||||||
|
status_end_time = None
|
||||||
|
try:
|
||||||
|
status_end_time = \
|
||||||
|
date_from_string_format(actor_status_json['endTime'],
|
||||||
|
date_formats)
|
||||||
|
except BaseException:
|
||||||
|
return False
|
||||||
|
if not status_end_time:
|
||||||
|
return False
|
||||||
|
curr_time = date_utcnow()
|
||||||
|
if status_end_time < curr_time:
|
||||||
|
return True
|
||||||
|
return False
|
4
tests.py
4
tests.py
|
@ -62,8 +62,8 @@ from flags import contains_pgp_public_key
|
||||||
from flags import is_group_actor
|
from flags import is_group_actor
|
||||||
from flags import is_group_account
|
from flags import is_group_account
|
||||||
from flags import is_right_to_left_text
|
from flags import is_right_to_left_text
|
||||||
from utils import actor_status_expired
|
from status import actor_status_expired
|
||||||
from utils import get_actor_status
|
from status import get_actor_status
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
from utils import valid_content_warning
|
from utils import valid_content_warning
|
||||||
from utils import data_dir
|
from utils import data_dir
|
||||||
|
|
53
utils.py
53
utils.py
|
@ -23,8 +23,6 @@ from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from followingCalendar import add_person_to_calendar
|
from followingCalendar import add_person_to_calendar
|
||||||
|
|
||||||
MAX_STATUS_LENGTH = 100
|
|
||||||
|
|
||||||
VALID_HASHTAG_CHARS = \
|
VALID_HASHTAG_CHARS = \
|
||||||
set('_0123456789' +
|
set('_0123456789' +
|
||||||
'abcdefghijklmnopqrstuvwxyz' +
|
'abcdefghijklmnopqrstuvwxyz' +
|
||||||
|
@ -5545,54 +5543,3 @@ def get_event_categories() -> []:
|
||||||
'THEATRE',
|
'THEATRE',
|
||||||
'WORKSHOPS_SKILL_SHARING'
|
'WORKSHOPS_SKILL_SHARING'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_actor_status(profile_json: {}) -> str:
|
|
||||||
"""returns the actor status if it exists
|
|
||||||
https://codeberg.org/fediverse/fep/src/branch/main/fep/82f6/fep-82f6.md
|
|
||||||
"""
|
|
||||||
if not profile_json.get('sm:status'):
|
|
||||||
return ''
|
|
||||||
status = ''
|
|
||||||
if isinstance(profile_json['sm:status'], str):
|
|
||||||
status = profile_json['sm:status']
|
|
||||||
elif isinstance(profile_json['sm:status'], dict):
|
|
||||||
if profile_json['sm:status'].get('content'):
|
|
||||||
possible_status = profile_json['sm:status']['content']
|
|
||||||
if isinstance(status, str):
|
|
||||||
status = possible_status
|
|
||||||
if status:
|
|
||||||
status = remove_html(status)
|
|
||||||
if len(status) > MAX_STATUS_LENGTH:
|
|
||||||
status = status[:MAX_STATUS_LENGTH]
|
|
||||||
status = standardize_text(status)
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
def actor_status_expired(actor_status_json: {}) -> bool:
|
|
||||||
"""Has the given actor status expired?
|
|
||||||
"""
|
|
||||||
if not actor_status_json.get('endTime'):
|
|
||||||
return False
|
|
||||||
if not isinstance(actor_status_json['endTime'], str):
|
|
||||||
return False
|
|
||||||
if 'T' not in actor_status_json['endTime'] or \
|
|
||||||
':' not in actor_status_json['endTime']:
|
|
||||||
return False
|
|
||||||
date_formats = (
|
|
||||||
"%Y-%m-%dT%H:%M:%S%z",
|
|
||||||
"%Y-%m-%dT%H:%M:%S%Z"
|
|
||||||
)
|
|
||||||
status_end_time = None
|
|
||||||
try:
|
|
||||||
status_end_time = \
|
|
||||||
date_from_string_format(actor_status_json['endTime'],
|
|
||||||
date_formats)
|
|
||||||
except BaseException:
|
|
||||||
return False
|
|
||||||
if not status_end_time:
|
|
||||||
return False
|
|
||||||
curr_time = date_utcnow()
|
|
||||||
if status_end_time < curr_time:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ from flags import is_system_account
|
||||||
from flags import is_group_account
|
from flags import is_group_account
|
||||||
from flags import is_valid_date
|
from flags import is_valid_date
|
||||||
from flags import is_premium_account
|
from flags import is_premium_account
|
||||||
from utils import actor_status_expired
|
from status import actor_status_expired
|
||||||
from utils import get_actor_status
|
from status import get_actor_status
|
||||||
from utils import get_person_icon
|
from utils import get_person_icon
|
||||||
from utils import text_mode_removals
|
from utils import text_mode_removals
|
||||||
from utils import replace_strings
|
from utils import replace_strings
|
||||||
|
|
Loading…
Reference in New Issue