Skip to content

Instantly share code, notes, and snippets.

@tora16e
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save tora16e/9484530 to your computer and use it in GitHub Desktop.

Select an option

Save tora16e/9484530 to your computer and use it in GitHub Desktop.
Extract the group list's ListDescription, ListName, and Members from `Notes`
#! 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(_)
#! 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)

Usage

  1. Export group list text file from Notes.
  2. run logfilter.py
  3. ADJUST the output.txt, if disorder group list.
  4. run tocsv.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment