Skip to content

Commit ebf8a38

Browse files
committed
Add merge-mutt-contacts.
1 parent c537660 commit ebf8a38

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎python3/merge-mutt-contacts.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Brandon Amos <http://bamos.github.io>
4+
# 2015.01.08
5+
6+
import argparse
7+
from collections import defaultdict
8+
import re
9+
10+
def merge_files(contacts_filenames):
11+
contents = defaultdict(list)
12+
for filename in contacts_filenames:
13+
with open(filename,'r') as f:
14+
group = None
15+
for line in f.readlines():
16+
line = line.strip()
17+
if len(line) == 0:
18+
continue
19+
r = re.search("^# (.*)$",line)
20+
if r:
21+
group = r.group(1)
22+
else:
23+
contents[group].append(line)
24+
for group in sorted(contents):
25+
print("# {}".format(group))
26+
print("\n".join(sorted(set(contents[group])))+"\n")
27+
28+
if __name__=='__main__':
29+
parser = argparse.ArgumentParser()
30+
parser.add_argument('contacts_filenames', type=str, nargs='+')
31+
args = parser.parse_args()
32+
33+
merge_files(args.contacts_filenames)

0 commit comments

Comments
 (0)