Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. CommonChar pins Category General
  2. CommonChar pins Contact Mark
  3. CommonChar pins Description 1st line
  4. CommonChar pins Description 2nd line
  5. CommonChar nails Category specific
  6. CommonChar nails Description 1st line
  7.  
  8. mainDict={}
  9. for dirName, subdirList, fileList in os.walk(sys.argv[1]):
  10. for eachFile in fileList:
  11. #excluding file names ending in .swp , swo which are creatied temporarily when editing in vim
  12. if not eachFile.endswith(('.swp','.swo','~')):
  13. #print eachFile
  14. filePath= os.path.join(dirName,eachFile)
  15. #print filePath
  16. with open(filePath, "r") as fh:
  17. contents=fh.read()
  18. items=re.findall("CommonChar.*$",contents,re.MULTILINE)
  19. for x in items:
  20. cc, group, topic, data = x.split(None, 3)
  21. data = data.split()
  22. group_dict = mainDict.setdefault(group, {'fileLocation': [filePath]})
  23. if topic in group_dict:
  24. group_dict[topic].extend(['</br>'] + data)
  25. else:
  26. group_dict[topic] = data
  27.  
  28. {'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