#!/usr/bin/env python # -*- coding: utf-8 -*- class Contents(object): text:list addStats:dict actions:list tags:list def __init__(self, item:list = None): self.tags = list() self.addStats = dict() self.actions = list() self.text = list() print(item) if item!=None: if "tags" in item: self.tags = self.__argumentToTagList(item["tags"]) if "mood_add" in item: for x,y in item["mood_add"].items(): self.addStats[x]=y if "actions" in item: for x in item["actions"]: self.actions.append(x) if "text" in item: for x in item["text"]: self.text.append(x) def __del__(self): del self.text del self.addStats del self.actions del self.Tags def hasTags(self, tagList): return self._hasTags(self.__argumentToTagList(tagList)) # TagList Info: # inside the .json File, when a Tag starts with "!", this ist a must have Tag # inside the TagList, when a tag has a "+", this tag must be in the .json entry # inside the TagList, when a tag has a "-", this tag must not be in the .json entry def _hasTags(self, tagList): # check High Required Tags for e in self.tags: if e[0:1]=="!": found=False for t in tagList: if t == e[1:] or t=="+"+e[1:]: found=True break if found==False: print("JSON-Tag not found: "+e) return 0 # check required Tags for t in tagList: tag = t found=False if t[0:1]=="+": for e in self.tags: if t[1:] == e or ("!"+t[1:])==e: found = True break if found==False: print("Script-Tag not found: "+t+" ... " + t[1:] + " | " + "!"+t[1:]) return 0 elif t[0:1]=="-": found=False for e in self.tags: if t[1:] == e: found = True break if found==False: return 0 if found==True: break # get num matching tags numFound = 0 for t in tagList: tag1 = t if tag1[0:1]=="+" or tag1[0:1]=="-" or tag1[0:1]=="*" or tag1[0:1]=="!" or tag1[0:1]=="~": tag1=tag1[1:] for e in self.tags: tag2 = e if tag2[0:1]=="+" or tag2[0:1]=="-" or tag2[0:1]=="*" or tag2[0:1]=="!" or tag2[0:1]=="~": tag2=tag2[1:] if tag1==tag2: numFound+=1 break return numFound def __argumentToTagList(self, arg): res = list() if isinstance(arg,list): for i in arg: tmp = self.__argumentToTagList(i) for j in tmp: res.append(j) else: tmp = arg.split(",") for i in tmp: res.append(i.strip().lower()) return res