Snake case

merge-requests/30/head
Bob Mottram 2021-12-26 12:31:47 +00:00
parent 257f29a815
commit 4215af54e3
4 changed files with 17 additions and 16 deletions

View File

@ -37,7 +37,7 @@ from utils import dmAllowedFromDomain
from utils import isRecentPost from utils import isRecentPost
from utils import getConfigParam from utils import getConfigParam
from utils import has_users_path from utils import has_users_path
from utils import validPostDate from utils import valid_post_date
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
@ -2217,7 +2217,7 @@ def _validPostContent(base_dir: str, nickname: str, domain: str,
return False return False
if 'Z' not in message_json['object']['published']: if 'Z' not in message_json['object']['published']:
return False return False
if not validPostDate(message_json['object']['published'], 90, debug): if not valid_post_date(message_json['object']['published'], 90, debug):
return False return False
summary = None summary = None

View File

@ -16,7 +16,7 @@ from datetime import datetime
from datetime import timedelta from datetime import timedelta
from datetime import timezone from datetime import timezone
from collections import OrderedDict from collections import OrderedDict
from utils import validPostDate from utils import valid_post_date
from categories import setHashtagCategory from categories import setHashtagCategory
from utils import dangerousSVG from utils import dangerousSVG
from utils import getFavFilenameFromUrl 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 # convert from YY-MM-DD HH:MM:SS+00:00 to
# YY-MM-DDTHH:MM:SSZ # YY-MM-DDTHH:MM:SSZ
postDate = pubDate.replace(' ', 'T').replace('+00:00', 'Z') 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: def parseFeedDate(pubDate: str) -> str:

View File

@ -47,7 +47,7 @@ from utils import removeInvalidChars
from utils import fileLastModified from utils import fileLastModified
from utils import isPublicPost from utils import isPublicPost
from utils import has_users_path from utils import has_users_path
from utils import validPostDate from utils import valid_post_date
from utils import getFullDomain from utils import getFullDomain
from utils import getFollowersList from utils import getFollowersList
from utils import isEvil from utils import isEvil
@ -4659,7 +4659,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
base_dir, nickname, domain, postId, base_dir, nickname, domain, postId,
recentPostsCache) recentPostsCache)
return None return None
if not validPostDate(announcedJson['published'], 90, debug): if not valid_post_date(announcedJson['published'], 90, debug):
_rejectAnnounce(announceFilename, _rejectAnnounce(announceFilename,
base_dir, nickname, domain, postId, base_dir, nickname, domain, postId,
recentPostsCache) recentPostsCache)

View File

@ -191,27 +191,27 @@ def get_locked_account(actor_json: {}) -> bool:
return False 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 """Whether there is a /users/ path (or equivalent) in the given string
""" """
usersList = get_user_paths() users_list = get_user_paths()
for usersStr in usersList: for users_str in users_list:
if usersStr in pathStr: if users_str in path_str:
return True return True
if '://' in pathStr: if '://' in path_str:
domain = pathStr.split('://')[1] domain = path_str.split('://')[1]
if '/' in domain: if '/' in domain:
domain = domain.split('/')[0] domain = domain.split('/')[0]
if '://' + domain + '/' not in pathStr: if '://' + domain + '/' not in path_str:
return False return False
nickname = pathStr.split('://' + domain + '/')[1] nickname = path_str.split('://' + domain + '/')[1]
if '/' in nickname or '.' in nickname: if '/' in nickname or '.' in nickname:
return False return False
return True return True
return False 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 """Returns true if the published date is recent and is not in the future
""" """
baselineTime = datetime.datetime(1970, 1, 1) 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") datetime.datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
except BaseException: except BaseException:
if debug: if debug:
print('EX: validPostDate invalid published date ' + str(published)) print('EX: valid_post_date invalid published date ' +
str(published))
return False return False
daysDiff = postTimeObject - baselineTime daysDiff = postTimeObject - baselineTime