From 928412c34cd22886f9b740e777ce87b0ba056593 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Mar 2021 19:53:22 +0000 Subject: [PATCH] Less verbose --- inbox.py | 6 +++--- newswire.py | 4 ++-- posts.py | 2 +- utils.py | 8 +++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/inbox.py b/inbox.py index 52cae2c1d..76e7aa55f 100644 --- a/inbox.py +++ b/inbox.py @@ -1608,7 +1608,7 @@ def _estimateNumberOfEmoji(content: str) -> int: def _validPostContent(baseDir: str, nickname: str, domain: str, messageJson: {}, maxMentions: int, maxEmoji: int, - allowLocalNetworkAccess: bool) -> bool: + allowLocalNetworkAccess: bool, debug: bool) -> bool: """Is the content of a received post valid? Check for bad html Check for hellthreads @@ -1627,7 +1627,7 @@ def _validPostContent(baseDir: str, nickname: str, domain: str, return False if 'Z' not in messageJson['object']['published']: return False - if not validPostDate(messageJson['object']['published']): + if not validPostDate(messageJson['object']['published'], 90, debug): return False if messageJson['object'].get('summary'): @@ -2305,7 +2305,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, nickname = handle.split('@')[0] if _validPostContent(baseDir, nickname, domain, postJsonObject, maxMentions, maxEmoji, - allowLocalNetworkAccess): + allowLocalNetworkAccess, debug): if postJsonObject.get('object'): jsonObj = postJsonObject['object'] diff --git a/newswire.py b/newswire.py index d54bcfe22..f59ca36cb 100644 --- a/newswire.py +++ b/newswire.py @@ -144,11 +144,11 @@ def _addNewswireDictEntry(baseDir: str, domain: str, ] -def _validFeedDate(pubDate: str) -> bool: +def _validFeedDate(pubDate: str, debug=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) + return validPostDate(postDate, 90, debug) def parseFeedDate(pubDate: str) -> str: diff --git a/posts.py b/posts.py index c088c178d..5a6bac82a 100644 --- a/posts.py +++ b/posts.py @@ -3962,7 +3962,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str, baseDir, nickname, domain, postId, recentPostsCache) return None - if not validPostDate(announcedJson['published']): + if not validPostDate(announcedJson['published'], 90, debug): _rejectAnnounce(announceFilename, baseDir, nickname, domain, postId, recentPostsCache) diff --git a/utils.py b/utils.py index 2d09cf0e0..35d42a4e8 100644 --- a/utils.py +++ b/utils.py @@ -100,7 +100,7 @@ def hasUsersPath(pathStr: str) -> bool: return False -def validPostDate(published: str, maxAgeDays=90) -> bool: +def validPostDate(published: str, maxAgeDays=90, debug=False) -> bool: """Returns true if the published date is recent and is not in the future """ baselineTime = datetime.datetime(1970, 1, 1) @@ -118,11 +118,13 @@ def validPostDate(published: str, maxAgeDays=90) -> bool: postDaysSinceEpoch = daysDiff.days if postDaysSinceEpoch > nowDaysSinceEpoch: - print("Inbox post has a published date in the future!") + if debug: + print("Inbox post has a published date in the future!") return False if nowDaysSinceEpoch - postDaysSinceEpoch >= maxAgeDays: - print("Inbox post is not recent enough") + if debug: + print("Inbox post is not recent enough") return False return True