Advertisement
AppajiC

LDAP

Feb 14th, 2023
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. with open("ldap_all_v1.txt") as f:
  2.     data = f.read().splitlines()
  3.  
  4.  
  5. def get_filename(row):
  6.     row = row.split(",")
  7.     file_name = str()
  8.     for cell in row:
  9.         if cell.startswith("ou="):
  10.             if len(file_name) != 0:
  11.                 file_name += "_"
  12.             file_name += cell[3:]
  13.     if len(file_name) == 0:
  14.         file_name = "misc"
  15.     return file_name + ".txt"
  16.  
  17.  
  18. mapping = {}
  19.  
  20. for row in data:
  21.     file_name = get_filename(row)
  22.     if file_name not in mapping:
  23.         mapping[file_name] = []
  24.     mapping[file_name].append(row)
  25.  
  26. for file_name in mapping:
  27.     with open(file_name, "w") as f:
  28.         f.write("\n".join(mapping[file_name]))
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement