Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CommonChar pins Category General
- CommonChar pins Contact Mark
- CommonChar pins Description 1st line
- CommonChar pins Description 2nd line
- CommonChar nails Category specific
- CommonChar nails Description 1st line
- mainDict={}
- for dirName, subdirList, fileList in os.walk(sys.argv[1]):
- for eachFile in fileList:
- #excluding file names ending in .swp , swo which are creatied temporarily when editing in vim
- if not eachFile.endswith(('.swp','.swo','~')):
- #print eachFile
- filePath= os.path.join(dirName,eachFile)
- #print filePath
- with open(filePath, "r") as fh:
- contents=fh.read()
- items=re.findall("CommonChar.*$",contents,re.MULTILINE)
- for x in items:
- cc, group, topic, data = x.split(None, 3)
- data = data.split()
- group_dict = mainDict.setdefault(group, {'fileLocation': [filePath]})
- if topic in group_dict:
- group_dict[topic].extend(['</br>'] + data)
- else:
- group_dict[topic] = data
- {'pins': {'Category': ['General'], 'Contact': ['Mark'], 'Description': ['1st', 'line', '2nd', 'line'] } , 'nails':{'Category':['specific'], 'Description':['1st line']}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement