-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_members
executable file
·62 lines (51 loc) · 1.64 KB
/
list_members
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import argparse
import sys
import time
import traceback
from solawi.mailinglists import (MAPPING, members_url)
from solawi.nextcloud import get_group_emails
from solawi.snapshots import (read_snapshot, save_snapshot)
def print_all():
for groupname in MAPPING:
print('---', groupname.upper())
users = get_group_emails(groupname)
print('\n'.join(a['mail'] for a in users))
def save():
timestamp = time.time()
users = read_snapshot()
for groupname in MAPPING:
if not groupname in users:
users[groupname] = []
old_users = users[groupname]
new_users = get_group_emails(
groupname, skip_these_users=old_users)
for new_user in new_users:
users[groupname] += [{
'id': new_user['id'],
'mail': new_user['mail'],
'ts': timestamp
}]
if new_users:
print('---', groupname.upper())
print('\n'.join(a['mail'] for a in new_users))
if MAPPING[groupname]:
print('''---
Please update here: {}'''.format(members_url(MAPPING[groupname])))
save_snapshot(users)
def main():
parser = argparse.ArgumentParser(description='List current members.')
parser.add_argument('--save',
action='store_true',
help='Save current snapshot of members. List new entries.')
args = parser.parse_args()
if args.save:
save()
sys.exit(0)
print_all()
if __name__ == "__main__":
try:
main()
except Exception as e:
traceback.print_exc()
sys.exit(1)