- Export group list text file from Notes.
- run logfilter.py
- ADJUST the output.txt, if disorder group list.
- run tocsv.py
Last active
August 29, 2015 13:57
-
-
Save tora16e/9484530 to your computer and use it in GitHub Desktop.
Extract the group list's ListDescription, ListName, and Members from `Notes`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! bin/env/python | |
| # -*- coding: utf-8 -*- | |
| title = ("ListDescription:", "ListName:", "Members:") | |
| with open('group.txt', encoding = 'utf-8') as lines,\ | |
| open('output.txt', 'w') as output: | |
| outputs = [line for line in lines for t in title if t in line] | |
| newoutputs = [] | |
| for v in outputs[:]: | |
| if "AdditionalMembers:" in v: | |
| pass | |
| elif "ExcludedMembers:" in v: | |
| pass | |
| elif title[2] == v[:len(title[2])]: | |
| v += "\n" | |
| v = v.replace("CN=", "") | |
| v = v.replace("/O=anotherName", "") | |
| newoutputs.append(v.replace("O=anotherName", "")) | |
| else: | |
| newoutputs.append(v) | |
| for _ in newoutputs: output.write(_) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! bin/env/python | |
| # -*- coding: utf-8 -*- | |
| import csv | |
| from itertools import cycle | |
| title = ("ListDescription:", "ListName:", "Members:") | |
| titles = cycle(title) | |
| outputs = [] | |
| elem = [] | |
| with open("output.csv", "w", newline="") as wf,\ | |
| open("output.txt") as rf: | |
| for line, t in zip(rf, titles): | |
| if t != title[2]: | |
| elem.append(line[len(t):].strip().rstrip("\n")) | |
| else: | |
| line = line[len(t):].split(",") | |
| for lin in line: | |
| try: | |
| elem[2] = lin.strip().strip("/").rstrip("\n") | |
| except IndexError: | |
| elem.append(None) | |
| elem[2] = lin.strip().strip("/").rstrip("\n") | |
| finally: | |
| outputs.append(elem[:]) | |
| else: | |
| elem.clear() | |
| else: | |
| cw = csv.writer(wf) | |
| cw.writerow(title) | |
| for o in outputs: | |
| cw.writerow(o) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment