Simplified extractData.generateIndex() logic. Tags are casefolded and capitalized than checked for duplicate entries

prototype-backendless-search-and-website-generator
Manish 4 years ago
parent c10fedcd44
commit ea5fda4de1

@ -24,7 +24,6 @@ along with SAAS. If not, see <https://www.gnu.org/licenses/>.
import glob import glob
import json import json
import os import os
import shutil
import sys import sys
from urllib.parse import quote as strToHtmlFmt from urllib.parse import quote as strToHtmlFmt
import zipfile import zipfile
@ -84,7 +83,7 @@ class extractData:
infoDict = self.extractActivityInfo(infoFiles[0], bundle) infoDict = self.extractActivityInfo(infoFiles[0], bundle)
self.bundlesInfoList.append(infoDict) self.bundlesInfoList.append(infoDict)
# FIXME: create seprate function for it # FIXME: create separate function for it
# extract and copy icon # extract and copy icon
activityName = infoDict.get("name") activityName = infoDict.get("name")
if type(activityName) == str: if type(activityName) == str:
@ -106,8 +105,6 @@ class extractData:
self.iconErrorBundles.append(bundlePath) self.iconErrorBundles.append(bundlePath)
bundle.close() bundle.close()
# FIXME: uncomment below function.
# Disabled sometime during development as time consuming
self.copyBundle(bundlePath, activityName) self.copyBundle(bundlePath, activityName)
bundle.close() bundle.close()
@ -152,45 +149,48 @@ class extractData:
be created for it. be created for it.
appends keys rather than replacing where multiple map to same appends keys rather than replacing where multiple map to same
""" """
# FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array' def generateIndex(self):
def generateIndex(self) for activity in json.loads(self.infoJson):
indexDict = {
for activity in json.loads(self.infoJson): "name": "",
indexDict = { "summary": "",
"name": "", "description": "",
"description" : "", "tags": ()
"tags": () }
}
name = activity.get("name")
name = activity.get["name"] if name is not None:
if name != None: indexDict["name"] = name
indexDict["name"] == name
summary = activity.get("summary")
summary = activity.get["summary"] if summary is not None:
if summary != None: indexDict["summary"] = summary
indexDict["summary"] = summary
description = activity.get["description"] description = activity.get("description")
if description != None: if description is not None:
indexDict["summary"] = ( indexDict["description"] = description
indexDict["summary"] + ' ' + description)
tags = []
tags = [] tagsKeys = ["tag", "tags", "category", "categories"]
tagsKeys = ["tag", "tags", "category", "categories"] for key in tagsKeys:
for key in tagsKeys: tagsString = activity.get(key)
tagsString = activity.get[tag] if tagsString is not None:
if tagsString != None: if tagsString.find(';') != -1:
for tag in tagString: tagsList = tagsString.split(';')
tag = tag.casefold().capitalize() else:
if tag not in tags: tagsList = tagsString.split()
tags.append[tag] for tag in tagsList:
infoDict["tags"] = tuple(tags) tag = tag.casefold().capitalize()
if tag not in tags:
self.indexDictList.append(indexDict) tags.append(tag)
self.indexJs = ( indexDict["tags"] = tuple(tags)
"search.assignIndex(" +
json.dumps(self.indexDictList, indent=4) + self.indexDictList.append(indexDict)
")" self.indexJs = (
) "search.assignIndex(" +
json.dumps(self.indexDictList, indent=4) +
")"
)
def generateInfoJson(self): def generateInfoJson(self):
self.infoJson = json.dumps(self.bundlesInfoList, indent=4) self.infoJson = json.dumps(self.bundlesInfoList, indent=4)

@ -1,4 +1,5 @@
import os import os
import shutil
def CallFuncInDir(Directory, Function, *args, **kwArgs): def CallFuncInDir(Directory, Function, *args, **kwArgs):

Loading…
Cancel
Save