import platform #Globals currOS = platform.platform() if currOS.find('Windows') == 0: LOCALBASE = 'D:/website/' #LOCALBASE = 'A:/test/' else: LOCALBASE = '/mnt/d/website/' TYPEFILE = LOCALBASE + "types.tsv" HIERFILE = LOCALBASE + "types.json" ERRFILE = LOCALBASE + "finderr.txt" flErr = open(ERRFILE, "w", encoding='latin1') def get_type_list(flTypes): typeList = [] stType = flTypes.read() lsIn = stType.split('\n') n = 0 for line in lsIn: n += 1 #get rid of leading tabs line = line.strip() # ignore blank lines if line == "": continue # or commented out lines if line[0] == "#": continue lsRec = line.split('\t') for liType in typeList: if lsRec[0] == liType[0]: stErr=lsRec[0]+" on line "+str(n)+" is a duplicate.\n" flErr.write(stErr) continue typeList.append(lsRec) return typeList def get_type(stIn, typeList, liFound, liNotFound): for lsRec in typeList: if stIn == lsRec[1]: # it's a parent get_type(lsRec[0], typeList, liFound, liNotFound) elif stIn == lsRec[0]: liFound.append(stIn) def show_tuple(t): n = 0 for item in t: if (n < len(t) -1): print("%s, " % item, end = "") else: print("%s" %item, end = "") n += 1 print("") def type_found(stIn, typeList): for lsRec in typeList: if lsRec[0] == stIn: return True return False def main(): flTypes = open(TYPEFILE, "r", encoding='latin1') if not flTypes: stErr = "Cannot read ", TYPEFILE flErr.write(stErr) return False typeList = get_type_list(flTypes) while True: myTypes = input("Type[s] requested (comma separated list):") if myTypes == "": break myTypes = myTypes.strip() liTypes = myTypes.split(',') liFound = [] liNotFound = [] for item in liTypes: item = item.strip() if type_found(item, typeList) == False: liNotFound.append(item) else: get_type(item, typeList, liFound, liNotFound) if liFound: show_tuple(liFound) if liNotFound: print("Types not found: ") show_tuple(liNotFound) # End main if __name__ == "__main__": main()