From 1dae3baccaa91c614d85de49e68164a1d7e4955c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 13 Aug 2019 22:32:18 +0100 Subject: [PATCH] Search for shared items --- daemon.py | 15 ++++++++++++--- webinterface.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/daemon.py b/daemon.py index 72f054fc..ed248f19 100644 --- a/daemon.py +++ b/daemon.py @@ -91,6 +91,7 @@ from webinterface import htmlEditProfile from webinterface import htmlTermsOfService from webinterface import htmlHashtagSearch from webinterface import htmlModerationInfo +from webinterface import htmlSearchSharedItems from shares import getSharesFeedForPerson from shares import outboxShareUpload from shares import outboxUndoShareUpload @@ -2213,7 +2214,7 @@ class PubServer(BaseHTTPRequestHandler): if '&' in searchStr: searchStr=searchStr.split('&')[0] searchStr=searchStr.replace('+',' ').replace('%40','@').replace('%3A',':').replace('%23','#').strip() - if searchStr.startswith('#'): + if searchStr.startswith('#'): # hashtag search hashtagStr= \ htmlHashtagSearch(self.server.baseDir,searchStr[1:],1, \ @@ -2225,9 +2226,8 @@ class PubServer(BaseHTTPRequestHandler): self.wfile.write(hashtagStr.encode('utf-8')) self.server.POSTbusy=False return - if '@' in searchStr: + elif '@' in searchStr: # profile search - print('Search: '+searchStr) nickname=getNicknameFromActor(self.path) if not self.server.session: self.server.session= \ @@ -2248,6 +2248,15 @@ class PubServer(BaseHTTPRequestHandler): self.wfile.write(profileStr.encode('utf-8')) self.server.POSTbusy=False return + else: + # shared items search + sharedItemsStr= \ + htmlSearchSharedItems(self.server.baseDir,searchStr) + if sharedItemsStr: + self._login_headers('text/html') + self.wfile.write(sharedItemsStr.encode('utf-8')) + self.server.POSTbusy=False + return self._redirect_headers(actorStr,cookie) self.server.POSTbusy=False return diff --git a/webinterface.py b/webinterface.py index 2236c3b2..f9fa325b 100644 --- a/webinterface.py +++ b/webinterface.py @@ -35,6 +35,49 @@ from content import getMentionsFromHtml from config import getConfigParam from skills import getSkills +def htmlSearchSharedItems(baseDir: str,searchStr: str) -> str: + sharedItemsForm='' + searchStrLower=searchStr.lower() + with open(baseDir+'/epicyon-profile.css', 'r') as cssFile: + sharedItemsCSS=cssFile.read() + sharedItemsForm=htmlHeader(sharedItemsCSS) + sharedItemsForm+='

Shared Items Search

' + resultsExist=False + for subdir, dirs, files in os.walk(baseDir+'/accounts'): + for handle in dirs: + if '@' not in handle: + continue + sharesFilename=baseDir+'/accounts/'+handle+'/shares.json' + if not os.path.isfile(sharesFilename): + continue + with open(sharesFilename, 'r') as fp: + sharesJson=commentjson.load(fp) + for name,sharedItem in sharesJson.items(): + matched=False + if sharedItem['location'].lower() in searchStrLower: + matched=True + elif searchStrLower in sharedItem['summary'].lower(): + matched=True + elif sharedItem['displayName'].lower() in searchStrLower: + matched=True + elif sharedItem['category'].lower() in searchStrLower: + matched=True + if matched: + sharedItemsForm+='
' + sharedItemsForm+='' + sharedItemsForm+='' + sharedItemsForm+='Item image' + sharedItemsForm+='

'+sharedItem['summary']+'

' + sharedItemsForm+='

Type: '+sharedItem['itemType']+' ' + sharedItemsForm+='Category: '+sharedItem['category']+' ' + sharedItemsForm+='Location: '+sharedItem['location']+'

' + sharedItemsForm+='
' + resultsExist=True + if not resultsExist: + sharedItemsForm+='
No results
' + sharedItemsForm+=htmlFooter() + return sharedItemsForm + def htmlModerationInfo(baseDir: str) -> str: infoForm='' with open(baseDir+'/epicyon-profile.css', 'r') as cssFile: