#!/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", "get-bank-accounts"]) 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.read(args.config) configdb = config['dolibarr'] 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))) elif args.selection == "get-bank-accounts": accounts = doli.get_bank_accounts(fields=['iban_prefix']) print("\n".join(map(lambda x: x[0], accounts)))