diff --git a/daemon.py b/daemon.py index 50f67118..19b1135a 100644 --- a/daemon.py +++ b/daemon.py @@ -65,7 +65,6 @@ from person import canRemovePost from person import personSnooze from person import personUnsnooze from posts import isModerator -from posts import isEditor from posts import mutePost from posts import unmutePost from posts import createQuestionPost @@ -169,6 +168,7 @@ from shares import getSharesFeedForPerson from shares import addShare from shares import removeShare from shares import expireShares +from utils import isEditor from utils import getImageExtensions from utils import mediaFileMimeType from utils import getCSS diff --git a/posts.py b/posts.py index 7f7f19ec..67c5a56a 100644 --- a/posts.py +++ b/posts.py @@ -92,34 +92,6 @@ def isModerator(baseDir: str, nickname: str) -> bool: return False -def isEditor(baseDir: str, nickname: str) -> bool: - """Returns true if the given nickname is an editor - """ - editorsFile = baseDir + '/accounts/editors.txt' - - if not os.path.isfile(editorsFile): - adminName = getConfigParam(baseDir, 'admin') - if not adminName: - return False - if adminName == nickname: - return True - return False - - with open(editorsFile, "r") as f: - lines = f.readlines() - if len(lines) == 0: - adminName = getConfigParam(baseDir, 'admin') - if not adminName: - return False - if adminName == nickname: - return True - for editor in lines: - editor = editor.strip('\n').strip('\r') - if editor == nickname: - return True - return False - - def noOfFollowersOnDomain(baseDir: str, handle: str, domain: str, followFile='followers.txt') -> int: """Returns the number of followers of the given handle from the given domain diff --git a/utils.py b/utils.py index 0d7bc527..f3e9643e 100644 --- a/utils.py +++ b/utils.py @@ -19,6 +19,60 @@ from calendar import monthrange from followingCalendar import addPersonToCalendar +def getHashtagCategory(baseDir: str, hashtag: str) -> str: + """Returns the category for the hashtag + """ + categoryFilename = baseDir + '/tags/' + hashtag + '.category' + if os.path.isfile(categoryFilename): + with open(categoryFilename, 'r') as fp: + categoryStr = fp.read() + if categoryStr: + return categoryStr + return '' + + +def setHashtagCategory(baseDir: str, hashtag: str, category: str) -> bool: + """Sets the category for the hashtag + """ + hashtagFilename = baseDir + '/tags/' + hashtag + '.txt' + if not os.path.isfile(hashtagFilename): + return False + categoryFilename = baseDir + '/tags/' + hashtag + '.category' + if os.path.isfile(categoryFilename): + with open(categoryFilename, 'w+') as fp: + fp.write(category) + return True + return False + + +def isEditor(baseDir: str, nickname: str) -> bool: + """Returns true if the given nickname is an editor + """ + editorsFile = baseDir + '/accounts/editors.txt' + + if not os.path.isfile(editorsFile): + adminName = getConfigParam(baseDir, 'admin') + if not adminName: + return False + if adminName == nickname: + return True + return False + + with open(editorsFile, "r") as f: + lines = f.readlines() + if len(lines) == 0: + adminName = getConfigParam(baseDir, 'admin') + if not adminName: + return False + if adminName == nickname: + return True + for editor in lines: + editor = editor.strip('\n').strip('\r') + if editor == nickname: + return True + return False + + def getImageExtensions() -> []: """Returns a list of the possible image file extensions """ diff --git a/webapp_column_left.py b/webapp_column_left.py index 5417e81a..d882400d 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -10,7 +10,7 @@ import os from shutil import copyfile from utils import getConfigParam from utils import getNicknameFromActor -from posts import isEditor +from utils import isEditor from webapp_utils import htmlPostSeparator from webapp_utils import getLeftImageFile from webapp_utils import getImageFile diff --git a/webapp_column_right.py b/webapp_column_right.py index 4dbbaac3..f20e3039 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -16,7 +16,7 @@ from utils import loadJson from utils import getConfigParam from utils import votesOnNewswireItem from utils import getNicknameFromActor -from posts import isEditor +from utils import isEditor from posts import isModerator from webapp_utils import getRightImageFile from webapp_utils import getImageFile diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index b07d739d..68574b1b 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -90,6 +90,8 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str: for subdir, dirs, files in os.walk(baseDir + '/tags'): for f in files: + if not f.endswith('.txt'): + continue tagsFilename = os.path.join(baseDir + '/tags', f) if not os.path.isfile(tagsFilename): continue diff --git a/webapp_post.py b/webapp_post.py index d8265583..366a56b6 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -17,12 +17,12 @@ from bookmarks import bookmarkedByPerson from like import likedByPerson from like import noOfLikes from follow import isFollowingActor -from posts import isEditor from posts import postIsMuted from posts import getPersonBox from posts import isDM from posts import downloadAnnounce from posts import populateRepliesJson +from utils import isEditor from utils import locatePost from utils import loadJson from utils import getCachedPostDirectory diff --git a/webapp_search.py b/webapp_search.py index 7ab20e18..fcfb1921 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -10,6 +10,7 @@ import os from shutil import copyfile import urllib.parse from datetime import datetime +from utils import isEditor from utils import loadJson from utils import getDomainFromActor from utils import getNicknameFromActor @@ -18,6 +19,7 @@ from utils import locatePost from utils import isPublicPost from utils import firstParagraphFromString from utils import searchBoxPosts +from utils import getHashtagCategory from feeds import rss2TagHeader from feeds import rss2TagFooter from webapp_utils import getAltPath @@ -663,13 +665,37 @@ def htmlHashtagSearch(cssCache: {}, hashtagSearchForm += '