From 71cf29629ae0d3d362e89c09ab4044694dade8ff Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 16 Dec 2021 21:22:44 +0000 Subject: [PATCH] Avoid duplicated function --- newswire.py | 4 ++-- webapp_column_right.py | 19 ++----------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/newswire.py b/newswire.py index b3a65fd44..907eb40c4 100644 --- a/newswire.py +++ b/newswire.py @@ -127,7 +127,7 @@ def limitWordLengths(text: str, maxWordLength: int) -> str: return result -def _getNewswireFaviconUrl(url: str) -> str: +def getNewswireFaviconUrl(url: str) -> str: """Returns a favicon url from the given article link """ if '://' not in url: @@ -147,7 +147,7 @@ def _downloadNewswireFeedFavicon(session, baseDir: str, link: str, debug: bool) -> bool: """Downloads the favicon for the given feed link """ - url = _getNewswireFaviconUrl(link) + url = getNewswireFaviconUrl(link) if '://' not in link: return False timeoutSec = 10 diff --git a/webapp_column_right.py b/webapp_column_right.py index 5f3b44d2c..bf1162270 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -22,6 +22,7 @@ from utils import getConfigParam from utils import removeDomainPort from utils import acctDir from posts import isModerator +from newswire import getNewswireFaviconUrl from webapp_utils import getRightImageFile from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter @@ -210,22 +211,6 @@ def _getBrokenFavSubstitute() -> str: return " onerror=\"this.onerror=null; this.src='/newswire_favicon.ico'\"" -def _getNewswireFavicon(url: str) -> str: - """Returns a favicon url from the given article link - """ - if '://' not in url: - return '/newswire_favicon.ico' - if url.startswith('http://'): - if not (url.endswith('.onion') or url.endswith('.i2p')): - return '/newswire_favicon.ico' - domain = url.split('://')[1] - if '/' not in domain: - return url + '/favicon.ico' - else: - domain = domain.split('/')[0] - return url.split('://')[0] + '://' + domain + '/favicon.ico' - - def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, translate: {}, positiveVoting: bool) -> str: """Converts a newswire dict into html @@ -252,7 +237,7 @@ def _htmlNewswire(baseDir: str, newswire: {}, nickname: str, moderator: bool, dateStrLink = dateStr.replace('T', ' ') dateStrLink = dateStrLink.replace('Z', '') url = item[1] - faviconUrl = _getNewswireFavicon(url) + faviconUrl = getNewswireFaviconUrl(url) faviconLink = '' if faviconUrl: faviconLink = \