From 4215af54e3f87a004643859c9aa5c9d37be0bf4e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 26 Dec 2021 12:31:47 +0000 Subject: [PATCH] Snake case --- inbox.py | 4 ++-- newswire.py | 4 ++-- posts.py | 4 ++-- utils.py | 21 +++++++++++---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/inbox.py b/inbox.py index 4e8fe3fe2..67757d087 100644 --- a/inbox.py +++ b/inbox.py @@ -37,7 +37,7 @@ from utils import dmAllowedFromDomain from utils import isRecentPost from utils import getConfigParam from utils import has_users_path -from utils import validPostDate +from utils import valid_post_date from utils import getFullDomain from utils import removeIdEnding from utils import getProtocolPrefixes @@ -2217,7 +2217,7 @@ def _validPostContent(base_dir: str, nickname: str, domain: str, return False if 'Z' not in message_json['object']['published']: return False - if not validPostDate(message_json['object']['published'], 90, debug): + if not valid_post_date(message_json['object']['published'], 90, debug): return False summary = None diff --git a/newswire.py b/newswire.py index 5f69b7730..e58b60d8a 100644 --- a/newswire.py +++ b/newswire.py @@ -16,7 +16,7 @@ from datetime import datetime from datetime import timedelta from datetime import timezone from collections import OrderedDict -from utils import validPostDate +from utils import valid_post_date from categories import setHashtagCategory from utils import dangerousSVG from utils import getFavFilenameFromUrl @@ -255,7 +255,7 @@ def _validFeedDate(pubDate: str, debug: bool = False) -> bool: # convert from YY-MM-DD HH:MM:SS+00:00 to # YY-MM-DDTHH:MM:SSZ postDate = pubDate.replace(' ', 'T').replace('+00:00', 'Z') - return validPostDate(postDate, 90, debug) + return valid_post_date(postDate, 90, debug) def parseFeedDate(pubDate: str) -> str: diff --git a/posts.py b/posts.py index d7c1182f9..59b998a0d 100644 --- a/posts.py +++ b/posts.py @@ -47,7 +47,7 @@ from utils import removeInvalidChars from utils import fileLastModified from utils import isPublicPost from utils import has_users_path -from utils import validPostDate +from utils import valid_post_date from utils import getFullDomain from utils import getFollowersList from utils import isEvil @@ -4659,7 +4659,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str, base_dir, nickname, domain, postId, recentPostsCache) return None - if not validPostDate(announcedJson['published'], 90, debug): + if not valid_post_date(announcedJson['published'], 90, debug): _rejectAnnounce(announceFilename, base_dir, nickname, domain, postId, recentPostsCache) diff --git a/utils.py b/utils.py index 0f0aff57a..21ba9aeaa 100644 --- a/utils.py +++ b/utils.py @@ -191,27 +191,27 @@ def get_locked_account(actor_json: {}) -> bool: return False -def has_users_path(pathStr: str) -> bool: +def has_users_path(path_str: str) -> bool: """Whether there is a /users/ path (or equivalent) in the given string """ - usersList = get_user_paths() - for usersStr in usersList: - if usersStr in pathStr: + users_list = get_user_paths() + for users_str in users_list: + if users_str in path_str: return True - if '://' in pathStr: - domain = pathStr.split('://')[1] + if '://' in path_str: + domain = path_str.split('://')[1] if '/' in domain: domain = domain.split('/')[0] - if '://' + domain + '/' not in pathStr: + if '://' + domain + '/' not in path_str: return False - nickname = pathStr.split('://' + domain + '/')[1] + nickname = path_str.split('://' + domain + '/')[1] if '/' in nickname or '.' in nickname: return False return True return False -def validPostDate(published: str, maxAgeDays: int, debug: bool) -> bool: +def valid_post_date(published: str, maxAgeDays: int, debug: bool) -> bool: """Returns true if the published date is recent and is not in the future """ baselineTime = datetime.datetime(1970, 1, 1) @@ -224,7 +224,8 @@ def validPostDate(published: str, maxAgeDays: int, debug: bool) -> bool: datetime.datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ") except BaseException: if debug: - print('EX: validPostDate invalid published date ' + str(published)) + print('EX: valid_post_date invalid published date ' + + str(published)) return False daysDiff = postTimeObject - baselineTime