Reduced extractData.generateIndex() code size

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

@ -153,51 +153,37 @@ class extractData:
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' # FIXME: Simplify logic: replace str, tuple, list etc. with 'string' & 'array'
def generateIndex( def generateIndex(self)
self,
infoToIndexMap={ for activity in json.loads(self.infoJson):
"name": ("name", "string"), indexDict = {
"summary": ("summary", "string"), "name": "",
"description": ("description", "string"), "description" : "",
"tag": ("tags", "array"), "tags": ()
"tags": ("tags", "array"), }
"categories": ("tags", "array"),
"category": ("tags", "array") name = activity.get["name"]
} if name != None:
): indexDict["name"] == name
unexpectedInputError = (
"main.py generateIndex() : expect only str, list or tuple as " summary = activity.get["summary"]
"kwargs -> value[1] but found " if summary != None:
) indexDict["summary"] = summary
description = activity.get["description"]
i2IMap = infoToIndexMap if description != None:
indexDict["summary"] = (
for obj in json.loads(self.infoJson): indexDict["summary"] + ' ' + description)
indexDict = {}
# Initialize keys with empty value tags = []
for k, v in i2IMap.items(): tagsKeys = ["tag", "tags", "category", "categories"]
if v[1] == "string": for key in tagsKeys:
indexDict[v[0]] = "" tagsString = activity.get[tag]
elif v[1] == "array": if tagsString != None:
indexDict[v[0]] = () for tag in tagString:
else: tag = tag.casefold().capitalize()
print(unexpectedInputError, v[1]) if tag not in tags:
sys.exit(1) tags.append[tag]
infoDict["tags"] = tuple(tags)
for k, v in obj.items():
if k in i2IMap:
# Add/Append to existing entries/keys
if i2IMap[k][1] == "string":
indexDict[i2IMap[k][0]] = (
indexDict[i2IMap[k][0]]+' '+v).strip(' ')
elif i2IMap[k][1] == "array":
if v.find(';') >= 0:
indexDict[i2IMap[k][0]] += tuple(v.split(';'))
else:
indexDict[i2IMap[k][0]] += tuple(v.split())
else:
print(unexpectedInputError, i2IMap[k][1])
sys.exit(1)
self.indexDictList.append(indexDict) self.indexDictList.append(indexDict)
self.indexJs = ( self.indexJs = (

Loading…
Cancel
Save