From 5c00e9c3aeea8f5e508432dce4ced8880152e3ae Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Feb 2020 11:13:29 +0100 Subject: [PATCH] Override roster url --- README.md | 13 +++++++------ sync_adherents_mailman.py | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cc05206..45a9aa7 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,13 @@ The re2o section defines parameter to connect to re2o api. ### Mailman section -| Parameter | Description | Default value | -|------------|--------------------------|------------------| -| `url` | url for mailman api | `localhost:8001` | -| `username` | username for mailman api | `restadmin` | -| `password` | password for mailman api | `restpassword` | -| `domain` | domain for mailing lists | `example.net` | +| Parameter | Description | Default value | +|--------------|-------------------------------------------|----------------------------------------------------------------------------------------------------| +| `url` | url for mailman api | `localhost:8001` | +| `username` | username for mailman api | `restadmin` | +| `password` | password for mailman api | `restpassword` | +| `domain` | domain for mailing lists | `example.net` | +| `roster_url` | roster url for getting and deleting email | None (`http://{mailman_url}/3.1/lists/{list_name}@{domain}/roster/member` will be used by default) | ### Sections for mailing-lists diff --git a/sync_adherents_mailman.py b/sync_adherents_mailman.py index b945a5d..5af986b 100644 --- a/sync_adherents_mailman.py +++ b/sync_adherents_mailman.py @@ -13,14 +13,14 @@ mailman_url = config.get('Mailman', 'url') mailman_username = config.get('Mailman', 'username') mailman_password = config.get('Mailman', 'password') domain = config.get('Mailman', 'domain') - +roster_url = config.get('Mailman', 'roster_url', fallback='http://{mailman_url}/3.1/lists/{list_name}@{domain}/roster/member') changed = int(open(filename).read()) if changed: for section in config.sections(): if section not in ["Re2o", "Mailman"] and config.getboolean(section, 'activate'): list_name = config.get(section, "list_name", fallback=section) - response1 = requests.get('http://{}/3.1/lists/{}@{}/roster/member'.format(mailman_url, list_name, domain), auth=(mailman_username, mailman_password)) + response1 = requests.get(roster_url.format(mailman_url=mailman_url, list_namelist_name, domain=domain), auth=(mailman_username, mailman_password)) if "entries" in response1.json(): entries = response1.json()['entries'] old_emails = [entry['email'] for entry in entries] @@ -28,7 +28,7 @@ if changed: emails_to_delete = [email for email in old_emails if email not in new_emails] if emails_to_delete: print("[..] Deleting non members from list {}".format(list_name)) - response = requests.delete('http://{}/3.1/lists/{}@{}/roster/member'.format(mailman_url, list_name, domain), auth=(mailman_username,mailman_password), params={'emails': emails_to_delete}) + response = requests.delete(roster_url.format(mailman_url=mailman_url, list_name=list_name, domain=domain), auth=(mailman_username,mailman_password), params={'emails': emails_to_delete}) print("[OK] Non members where deleted from list {}".format(list_name)) else: print("[INFO] No member to delete for list {}".format(list_name))