1234567891011121314151617181920212223242526272829303132333435 |
- #!/usr/bin/python3
- import argparse
- import configparser
- import psycopg2
- import fcntoolbox.dolibarr as dolibarr
- parser = argparse.ArgumentParser()
- parser.add_argument("selection", type=str,
- choices=["get-adherents", "get-subscribers"])
- parser.add_argument("-c", "--config", type=str,
- default="/etc/fcntoolbox/config.ini",
- help="specify a configuration file")
- parser.add_argument("--product", type=str,
- default="%",
- help="product code (can contain %)")
- args = parser.parse_args()
- config = configparser.RawConfigParser()
- config.sections()
- config.read(args.config)
- configdb = config['database']
- conn = psycopg2.connect(database=configdb['database'],
- user=configdb['user'], password=configdb['password'], host=configdb['host'])
- doli = dolibarr.Instance(conn)
- if args.selection == "get-adherents":
- adherents = doli.get_adherent(fields = ['email'])
- print("\n".join(map(lambda x: x[0], adherents)))
- elif args.selection == "get-subscribers":
- subscribers = doli.get_subscriber(args.product, ['email'])
- print("\n".join(map(lambda x: x[0], subscribers)))
|